Math for AI course · Lesson 31 of 180
A Basis Gives AI Vectors a Reversible Coordinate System
Test whether vectors form a basis, calculate coordinates in a new frame, and see how a linear model keeps the same score after a coordinated change.
The same point in a model’s two-dimensional representation can be written as
(1, 7) or (3, 2). Both pairs can describe the vector whose first coordinate
is 1 and second is 7, provided we say which coordinate system we are using.
The first pair uses the familiar horizontal and vertical axes. The second uses
two slanted basis vectors. A basis is what makes that alternative a
complete, non-ambiguous way to describe every vector in the space.
By the end, you will be able to check whether a set of vectors is a basis, calculate a vector’s coordinates in that basis, and explain what must change in a linear model when its input coordinates change.
Learning outcome: Verify a basis and express a vector in basis coordinates.
This lesson builds on linear independence and span: a basis combines both ideas. The treatment follows Section 2.6 of Mathematics for Machine Learning, while the numerical example, model-score calculation, explorer, and questions below are original.
A basis has just enough directions
Work in a finite-dimensional vector space. A set of vectors is a basis for a space when it satisfies two tests:
- It spans the space: every vector in the space can be built from the set using a linear combination.
- It is linearly independent: none of its vectors is redundant; the only linear combination that produces the zero vector uses zero for every coefficient.
Together, these conditions mean the set has enough directions to reach every vector and has no extra direction that creates ambiguity. The book’s Section 2.6 gives equivalent characterizations: a basis is a minimal spanning set and a maximal linearly independent set, and each vector has a unique linear combination in that basis.
In , a basis has exactly vectors. For a smaller subspace, the basis has as many vectors as the subspace has independent directions. Two vectors may be a basis for a plane inside , for example, without being a basis for all of .
Why coordinates become unique
Suppose are a basis and is any vector in the space. Spanning guarantees that at least one set of coefficients can represent it:
Now imagine another set gives the same vector. Subtracting the two expressions gives
Because the basis vectors are linearly independent, every coefficient in this zero combination must be zero. So for each . The coordinates are unique because the basis has no redundant direction.
We write the coordinate column as . The subscript matters: it says which basis gives those coordinates. The vector and its coordinate column are related, but they are not interchangeable objects.
Compute a change of coordinates
Take these two vectors in :
Put the basis vectors in the columns of a matrix:
They are independent: the determinant is , which is not zero. Since there are two independent vectors in , they also span the plane, so they form a basis.
Find the coordinates of . The coordinate column must satisfy . Writing turns that matrix equation into two ordinary equations:
Subtract the first equation from the second: , so . Then , so . Check the reconstruction directly:
The coordinate pair means “three steps along and two along .” It names the same endpoint that standard coordinates call .
One vector, two coordinate systems
Coordinates in the selected basis: (1, 7)
Vector in standard coordinates: (1, 7)
v = c₁b₁ + c₂b₂
Coordinates in the selected basis: (1, 7)The explorer starts with standard coordinates. Use its keyboard-accessible selector to switch to the tilted basis: the arrow to ends at the same point, while the displayed coordinates change from to . The caption and readout expose the result as text as well as in the diagram.
Let NumPy solve the coordinate equation
For a larger basis, the same relationship is a linear system. Store basis vectors as columns, then solve :
import numpy as np
B = np.array([[1, -1],
[1, 2]]) # columns are b1=(1, 1) and b2=(-1, 2)
v = np.array([1, 7])
rank = np.linalg.matrix_rank(B)
coordinates = np.linalg.solve(B, v)
reconstructed = B @ coordinates
print(rank) # 2: full rank in R^2
print(coordinates) # [3. 2.]
print(np.allclose(reconstructed, v)) # True
For this square matrix in , full rank means its two columns are
independent, which is enough to establish a basis. numpy.linalg.solve returns
the solution of the square, full-rank system; NumPy raises LinAlgError when
the matrix is singular or not square. The rank result here is a numerical
diagnostic: NumPy estimates rank through singular values and a tolerance, so
near-dependent floating-point data may need a tolerance chosen for the scale
and measurement precision of the application. See the official
NumPy matrix_rank reference
and solve reference.
For exact small integer examples, a hand calculation such as the determinant above gives a crisp proof. For real-valued data, a reconstruction check is useful but is not a basis test on its own: a singular matrix can still reconstruct some vectors. Check that the matrix has the right shape and full rank as well.
A model’s weights must follow its coordinates
A basis change can clarify a model’s internal representation, but the change has to be coordinated with the operations that consume it. Consider a linear score with and . In standard coordinates the score is
In the tilted basis, with . Then
The matching weights in the new coordinates are , and the score remains . If the original weights were applied directly to the new coordinate pair, the score would become . The representation was re-described, but the model’s parameters were not updated to match.
This equality is exact for the linear score shown. A neural network that applies nonlinear activations, normalization, or other operations between layers may not preserve its behavior under an arbitrary basis change. In practice, a representation’s coordinates are tied to the learned parameters and operations around it; changing one piece alone can change predictions.
When a candidate set fails
Two candidate vectors can point in the same direction and still look like two entries in a list:
The second is twice the first. Their determinant is zero, and their span is only the line , not the whole plane. The vector cannot be reached at all using them. Even a reachable vector has ambiguous coordinates: can be written as or .
Nearly parallel vectors can pass an exact independence test yet produce coordinates that are sensitive to small measurement or rounding changes. That is a numerical conditioning issue: the mathematical coordinates may be unique while their computed values are fragile. A rank estimate and a reconstruction residual answer different questions, so interpret both in the context of data precision.
A basis is therefore more than a compact list of vectors. It is a contract: every vector in the chosen space is reachable, and only one coordinate tuple describes each vector once the basis is fixed. The number of basis vectors then gives the space’s dimension, the next step in connecting linear algebra to model representations.
Check your understanding
Question 1
Do (2, 0) and (1, 3) form a basis for ℝ²? Show the independence check and explain why it is sufficient here.
Show the step-by-step solution
Put the vectors into a matrix as columns:
Its determinant is , which is nonzero, so the columns are linearly independent. There are two independent vectors in ; they span the plane and form a basis.
Question 2
Using b₁=(1, 1) and b₂=(−1, 2), find the basis coordinates of v=(1, 7). Verify the answer by reconstruction.
Show the step-by-step solution
Set . Comparing components gives and . Subtract the first equation from the second: , hence . Then . Reconstruct: . The coordinates are .
Question 3
In the same tilted basis, what vector do the coordinates (−2, 4) represent in standard coordinates?
Show the step-by-step solution
Substitute the coordinates into the linear combination: . The first component is ; the second is . So the represented vector is .
Question 4
Why can a basis give only one coordinate tuple for a vector?
Show the step-by-step solution
Suppose both and . Subtract the expressions to get . Linear independence says the only coefficients that make the zero vector are all zero. Therefore each , so for every basis vector.
Question 5
Let a₁=(1, 2) and a₂=(2, 4). Can they represent (3, 1)? Give one reachable vector that has more than one coordinate description.
Show the step-by-step solution
Both vectors lie on , so every linear combination also lies on that line. Since does not satisfy , it is unreachable. The reachable vector has two descriptions: and . The dependence causes both failure to span the plane and non-unique coordinates for some reachable vectors.
Question 6
In ℝ³, let a₁=(1, 0, 1), a₂=(0, 1, 1), and a₃=(1, 1, 2). Is this a basis for all of ℝ³? Could a₁ and a₂ be a basis for a smaller space?
Show the step-by-step solution
Notice that , so the three-vector set is dependent. It cannot be a basis for ; it also spans at most a plane. The first two vectors are independent, so they form a basis for their span, the plane generated by and .
Question 7
For B=[[1, −1], [1, 2]] with basis vectors stored as columns, what does `np.linalg.solve(B, [1, 7])` return, and what should you verify afterward?
Show the step-by-step solution
The system is and . Solving gives
. Reconstruct with to check it returns
; a numerical residual check such as np.allclose(B @ coordinates, v)
can catch a transpose or indexing mistake. Also check that is square and
full rank before treating its columns as a basis of .
Question 8
A linear model scores v=(1, 7) using w=(2, 1). If coordinates change to c=(3, 2) in the tilted basis, what matching weights preserve the score? What happens if the old weights are left unchanged?
Show the step-by-step solution
Write . Then , so the new weights are . The score is , matching the old score . If the old weights are applied unchanged to , the score is , so the model’s output changes.