Basis and Dimension
A basis of a subspace is a set of vectors that spans it with no redundancy. Every vector then has unique coordinates with respect to the basis, and the number of basis vectors, the dimension, does not depend on which basis you pick.
Basis
A set is a basis of a subspace of if
- it spans (Spans), and
- it is linearly independent (Linear Independence).
Spanning means "enough vectors to reach everything"; independence means "no vector too many". The standard basis of is , , , , but has infinitely many other bases.
Coordinates. If is a basis of , every can be written as in exactly one way (spanning gives existence, independence gives uniqueness). The numbers are the coordinates of relative to , written .
Dimension
Theorem (exchange lemma). If a subspace is spanned by vectors, then any independent set in has at most vectors.
Sketch: put spanning vectors as columns of and independent vectors of as columns of . Each is a combination of the spanning vectors, so for some matrix . If , the homogeneous system has a non-zero solution (more unknowns than equations), and then contradicts independence. So .
Applying this both ways to two bases shows they have the same number of elements. That common number is the dimension . Examples: , a line through has dimension 1, a plane through dimension 2, and .
Useful consequences in a subspace of dimension :
| Statement | |
|---|---|
| any independent vectors in form a basis | no need to check spanning |
| any vectors that span form a basis | no need to check independence |
| more than vectors in are dependent | |
| fewer than vectors cannot span | |
| a subspace has , with equality only if |
Finding a basis of a span
To get a basis of , put the vectors as columns of and row-reduce. The original columns of in the pivot positions form a basis. (Use the original vectors, not the columns of the reduced matrix; row operations change the span of the columns.)
from sympy import Matrix
vs = [Matrix([1, 2, 0, 1]), Matrix([2, 4, 0, 2]), Matrix([0, 1, 1, 0]),
Matrix([1, 3, 1, 1]), Matrix([0, 0, 1, 5])]
A = Matrix.hstack(*vs)
R, piv = A.rref()
print("pivot columns:", piv)
basis = [vs[j] for j in piv]
print("basis:", [list(b) for b in basis])
print("dimension of the span:", len(basis))pivot columns: (0, 2, 4)
basis: [[1, 2, 0, 1], [0, 1, 1, 0], [0, 0, 1, 5]]
dimension of the span: 3
and were the redundant ones.
Coordinates relative to a basis
To find , solve the system , where the basis vectors are the columns of . In with an -vector basis, is square and invertible:
from sympy import Matrix
b1, b2 = Matrix([2, 1]), Matrix([-1, 1])
B = Matrix.hstack(b1, b2)
w = Matrix([4, 5])
c = B.solve(w)
print("coordinates of w in basis {b1, b2}:", list(c))
print("check:", list(c[0] * b1 + c[1] * b2))coordinates of w in basis {b1, b2}: [3, 2]
check: [4, 5]
So in the standard basis is in the basis : same vector, different coordinates.
In software
- Local axes in games. An object's orientation is a basis: its right, up and forward vectors. The world position of a point with local coordinates is (plus the object's origin). Going back from world to local is solving ; for an orthonormal basis that is just three dot products (Local, World and View Space).
- Embedding dimension. An LLM embedding with 4096 coordinates lives in , but the vectors a model actually produces often cluster near a much lower-dimensional subspace, which is why dimensionality reduction loses little (Embeddings and Cosine Similarity).
- PCA chooses a better basis. Principal Component Analysis replaces the original feature axes by an orthonormal basis ordered by variance, then keeps the first few coordinates (PCA).
- Compression. JPEG rewrites 8×8 pixel blocks in a cosine basis where most coordinates are tiny and can be dropped.
Exercises
Exercise 1: Is it a basis of ?
Is a basis of ? Is ?
Answer
The first is a basis; the second is not.
Solution
Three vectors in form a basis exactly when they are independent (rank 3).
from sympy import Matrix
print(Matrix([[1, 1, 0], [0, 1, 1], [1, 0, 1]]).rank())
print(Matrix([[1, 4, 7], [2, 5, 8], [3, 6, 9]]).rank())3
2
In the second set, .
Exercise 2: Dimension of a plane
Find a basis and the dimension of the subspace of given by .
Answer
Basis ; dimension 3.
Solution
One equation in four unknowns: is a pivot, are free. gives
The three vectors are independent (each has a 1 where the others have 0), so the dimension is 3.
Exercise 3: Coordinates
Find the coordinates of with respect to the basis .
Answer
.
Solution
from sympy import Matrix
B = Matrix([[1, 0, 1], [1, 1, 0], [0, 1, 1]])
print(list(B.solve(Matrix([1, 7, 5]))))[3/2, 11/2, -1/2]
Exercise 4: Extend to a basis
Extend to a basis of by adding standard basis vectors. (Hint: reduce and keep the pivot columns.)
Answer
Add and : .
Solution
The pivot columns of the 4×6 matrix are the first two (the given vectors) plus the first standard vectors that add something new.
from sympy import Matrix, eye
A = Matrix.hstack(Matrix([1, 1, 0, 0]), Matrix([0, 0, 1, 1]), eye(4))
print(A.rref()[1])(0, 1, 2, 4)
Columns 2 and 4 are and .
Test yourself
What is the dimension of ?
- 0
- 1
- 2
- 3
To get a basis of the span of 's columns, which vectors do you take?
- The original columns of in the pivot positions
- The pivot columns of
- The rows of
- All columns of
In a 5-dimensional subspace , five independent vectors are chosen. Do they form a basis of ?
- Not necessarily
- Only if they are orthogonal
- Only if they include the standard basis
- Yes, automatically