Bases, dimension, and rank
基、维数与秩
Count independent directions and distinguish coordinate length, dimension, matrix rank, and approximate numerical redundancy.
basis-rankAnother coordinate need not add information
Suppose two data columns record the same measurement in meters and centimeters. The second is always 100 times the first. There are two columns but no additional independent direction. Conversely, a plane need not use horizontal and vertical coordinate axes: two nonparallel directions still describe every point.
A basis supplies nonredundant coordinate directions. Dimension counts those directions. Rank describes the dimension actually spanned by a matrix’s rows or columns. They concern independence, not merely array shape under different names.
Express everything without ambiguity
Vectors are linearly independent when a zero linear combination forces every coefficient to be zero:
If they also span , they form a basis. Spanning guarantees a representation for every vector, and independence makes it unique. Subtract two representations of the same , with coefficients and , to obtain a zero combination. Independence then forces for every coordinate. MML, Sections 2.5–2.6
For example, and form a basis of the plane:
The same vector has standard coordinates and new-basis coordinates . Changing basis changes coordinates, not the represented vector. Every basis of a finite-dimensional space contains the same number of vectors, its dimension. The zero space contains only zero, has an empty basis, and has dimension 0.
For , rank is the dimension of its column space and also its row space. It obeys:
The second relation is rank–nullity: the kernel dimension is the input dimension minus the image dimension. For , column two is twice column one, while columns one and three are independent. Rank is 2 and nullity is 1. MML, Section 2.6, Deep Learning, Section 2.4
Count pivots, not nonzero columns
This complete Python program counts pivots by elimination. Exact fractions suit small integer or rational examples; a very small value is not automatically treated as zero.
from fractions import Fraction as F
def exact_rank(rows):
if not rows:
return 0
n = len(rows[0])
if any(len(row) != n for row in rows):
raise ValueError("ragged matrix")
a = [[F(x) for x in row] for row in rows]
r = 0
for col in range(n):
pivot = next((i for i in range(r, len(a)) if a[i][col] != 0), None)
if pivot is None:
continue
a[r], a[pivot] = a[pivot], a[r]
scale = a[r][col]
a[r] = [x / scale for x in a[r]]
for i in range(r + 1, len(a)):
factor = a[i][col]
a[i] = [x - factor * y for x, y in zip(a[i], a[r])]
r += 1
if r == len(a):
break
return r
assert exact_rank([[1, 2, 0], [0, 0, 1]]) == 2
assert exact_rank([[1, 2], [2, 4]]) == 1
assert exact_rank([[0, 0], [0, 0]]) == 0
epsilon = F(1, 10**12)
assert exact_rank([[1, 1], [1, 1 + epsilon]]) == 2
Naive elimination takes scalar operations and space for the copied matrix. Fraction bit lengths can grow, so this is not a complete bit-complexity estimate. The program explains rank rather than replacing decomposition algorithms for large floating-point datasets.
Exact and numerical rank answer different questions
In the final example, any nonzero gives exact rank 2. If measurement error greatly exceeds , the second direction may not carry reliable information. Numerical rank commonly depends on singular-value thresholds, matrix scale, and accuracy requirements; reasonable thresholds can yield different approximate ranks.
Full rank does not automatically imply invertibility. A matrix is full rank at rank 2 but cannot have an ordinary two-sided square inverse. State its shape and whether the question concerns independent columns, independent rows, or uniqueness of a solution.
A hidden representation with thousands of coordinates need not vary in that many independent directions on a particular dataset. Rank also does not measure how much task-relevant information survives. Small directions can matter for classification, and large directions can reflect nuisance variation.
Test your understanding through uniqueness
- Can three vectors in a plane all be linearly independent? Answer: no; the ambient dimension is 2.
- Can a set containing the zero vector be independent? Answer: no. Assigning a nonzero coefficient to zero gives a nontrivial zero combination.
- Which direction spans the example matrix’s kernel? Answer: .
- If all four columns are nonzero, must rank be 4? Answer: no. The columns may be multiples or satisfy another linear dependence.
Turning redundancy into computational savings
Low-rank factorization expresses a large matrix as a product of smaller matrices, potentially reducing storage and multiplication costs. PCA, low-rank adaptation, and matrix completion exploit related structures under different assumptions. A low-rank study should identify the matrix, rank definition, approximation error, and task results. Compression ratio alone does not establish success.
Make a prediction, then check
A real matrix has five columns and rank three. What is its nullity?
Learning objectives
- Explain bases and unique coordinates through spanning and linear independence.
- Calculate a small matrix’s rank and nullity, distinguishing exact from numerical rank.
Prerequisites & connections
Explore related knowledge →References
- Mathematics for Machine Learning — mathematical foundations (2024-01-15 draft)
Marc Peter Deisenroth; A. Aldo Faisal; Cheng Soon Ong · 2020 - Deep Learning — Chapter 2: Linear Algebra
Ian Goodfellow; Yoshua Bengio; Aaron Courville · 2016
Version1 · Editorial status: Recorded technical checks completed
View technical check record (AI)
Codex · 2026-09-05 · Codex technical check: cited-source comparison, re-derivation and recalculation, bilingual argument comparison, and executed Python assertions; no independent human peer review.
- Recalculated basis coordinates (2,2), matrix rank 2, and kernel direction (−2,1,0); checked the input dimension in rank–nullity.
- Clarified trivial-space wording to avoid confusion with a matrix kernel; checked rational elimination, numerical-rank thresholds, and the absence of a two-sided inverse for nonsquare full-rank matrices.
- Compared arguments, numbers, examples, limitations, and exercise answers across languages; structural validation separately compares display formulas, code, sources, and sections. No independent human peer review.
Source locations checked:
- Mathematics for Machine Learning — mathematical foundations (2024-01-15 draft) · §2.5–2.6, PDF pp. 46–54, including rank–nullity on p. 53
- Deep Learning — Chapter 2: Linear Algebra · §2.4: span, independence, and matrix shape
Related topics