Basis and Rank
§2.5 asked which vectors in a pile are redundant. This section asks the two follow-up questions that matter: what is the smallest set that still builds everything, and how many vectors is that?
The answers are the basis and the rank, and the rank turns out to be the single most informative number you can extract from a matrix. It decides invertibility, solvability, the dimension of the image, the dimension of the null space, and — once §4.6 arrives — how well the matrix can be compressed.
What you’ll learn
Section titled “What you’ll learn”- Generating set, span, and what makes a generating set minimal.
- Four equivalent ways to say “basis”, and why the fourth one (unique coordinates) is the useful one.
- Why every basis of a space has the same size, which is what makes dimension well defined.
- Rank, and the six properties of it that do all the work.
- Why a basis is not unique but the rank is — and how to find a basis of a subspace in three steps.
Intuition: describing any location in a city
Section titled “Intuition: describing any location in a city”Take a city on a grid. “Three blocks east, two blocks north” locates anything. Two directions are enough, and neither is redundant — drop “north” and the whole northern half of the city becomes unreachable.
That pair is a basis: enough to reach everything (a generating set), with nothing to spare (linearly independent). Add “four blocks north-east” as a third direction and you still reach everything, but the set is no longer minimal — the description of a location stops being unique, because you can now get there in more than one way.
Uniqueness is what you buy by insisting on minimality, and it is the whole reason bases matter.
flowchart TD A["a set of vectors"] --> S["SPAN: everything
they can build"] S --> Q1{"does the span
cover all of V?"} Q1 -->|"no"| NG["not a generating set"] Q1 -->|"yes"| GS["GENERATING SET"] GS --> Q2{"is it minimal?
equivalently: independent?"} Q2 -->|"no"| RED["redundant — coordinates
are NOT unique"] Q2 -->|"yes"| BAS["BASIS"] BAS --> D["its size is the DIMENSION,
the same for every basis"] BAS --> U["every vector has EXACTLY ONE
coordinate representation"]
The math
Section titled “The math”Generating set and span
Section titled “Generating set and span”Given a vector space and a set :
- If every can be written as a linear combination of , then is a generating set of .
- The set of all linear combinations of vectors in is the span of .
- If spans we write , or .
The span is always a subspace — it contains (all coefficients zero) and it is closed under both operations by construction. So “span” is the standard way to manufacture a subspace, and §2.4’s closing remark said every subspace arises this way.
A generating set of is minimal if there is no smaller set that still spans . Every linearly independent generating set is minimal, and is called a basis of .
The book then gives four equivalent characterisations, and they are worth knowing as a group because different problems make different ones easy to check. For nonempty, these are the same statement:
- is a basis of .
- is a minimal generating set.
- is a maximal linearly independent set — adding any other vector of makes it dependent.
- Every is a linear combination of vectors from , and that combination is unique:
Characterisation 3 is the sharpest framing: a basis is squeezed from both sides. Too few vectors and it does not span; too many and it is dependent. It sits exactly at the boundary — minimal among spanning sets and maximal among independent sets at the same time.
Characterisation 4 is the one you actually use. Unique coordinates are what make “the coordinates of ” a well-defined phrase, and §2.7 builds the entire transformation-matrix machinery on top of it.
Dimension
Section titled “Dimension”Every vector space has a basis, and there are many of them — no basis is unique. But all of them have the same number of elements, and that number is the dimension .
That invariance is what makes dimension meaningful, and it is not obvious. Two people can pick totally different bases of and both will have exactly three vectors.
For a subspace : , with equality if and only if . So a proper subspace is always strictly lower dimensional — there is no “same-dimension proper subspace”.
Finding a basis of a subspace
Section titled “Finding a basis of a subspace”Three steps, and the book states them as a recipe. For :
- Write the spanning vectors as the columns of a matrix .
- Determine the row-echelon form of .
- The spanning vectors belonging to the pivot columns are a basis of .
This is §2.5’s independence test, reused verbatim. Same computation, different question: there we asked whether the set was independent, here we ask which subset is.
The number of linearly independent columns of equals the number of linearly independent rows, and that common number is the rank, .
That equality is remarkable and easy to skate past. There is no obvious reason a matrix should have as many independent rows as columns — the two counts are about different vectors living in different spaces — and yet they always agree.
The six properties that do the work:
| property | statement |
|---|---|
| row rank = column rank | |
| image dimension | the columns span a subspace with ; this is the image or range |
| row space dimension | the rows span with |
| invertibility | is invertible iff |
| solvability | is solvable iff |
| null-space dimension | the solutions of form a subspace of dimension |
A matrix has full rank when — the largest possible for its shape — and is rank deficient otherwise.
The solvability property is the one §2.1’s classification code used, and the null-space property is where §2.3’s free-variable count came from. Both were stated there and are proved here.
Worked example by hand
Section titled “Worked example by hand”The book’s Example 2.17. Find a basis of the subspace spanned by
Write them as columns and reduce:
Pivots sit in columns 1, 2 and 4. So is a basis of , and . Column 3 is not a pivot column, so is a combination of the others — and indeed , which you can check entry by entry: ✓, ✓, ✓, ✓, ✓.
The book’s Example 2.18, two rank calculations. First,
has two independent rows and two independent columns, so . Note the third column is the sum of the first two, and the third row is zero — two different-looking redundancies, one rank.
Second,
so . It is and rank 2, hence not invertible — and follows, though we do not have determinants until §4.1.
Row rank equals column rank, checked on a rectangle. Take
Rows: the second is twice the first, so one independent row. Columns: all four are multiples of , so one independent column. Both give rank 1, from completely different counting.
And the derived quantities for this : image dimension (a line in ), null-space dimension , and it is rank deficient because .
See it move
Section titled “See it move”A basis is a coordinate system, and changing it changes the coordinates of a point without moving the point. The white vector below is fixed; the amber basis rotates, and the coordinates rewrite themselves to compensate.
Two things to watch. The coordinates swing wildly while the white dot never moves — the point is basis-independent, the description is not. And when the two amber vectors line up, the determinant passes through zero and the sketch says “not a basis”: at that instant they span only a line, so most points have no coordinates at all rather than non-unique ones.
Extracting a basis from a spanning set
Section titled “Extracting a basis from a spanning set”The book’s three-step recipe, run one vector at a time. Accepted vectors turn green and become part of the basis; rejected ones were already inside the span.
The third is 2e1 + 3e2 and gets rejected; the fourth adds the missing direction. Rank 3 in R-3, so the accepted set is a basis of the whole space.
Note what happened: the third vector was rejected, not the last. The recipe walks left to right and keeps whatever is new, so the rejected vector is wherever the redundancy first becomes detectable — not necessarily at the end.
From scratch
Section titled “From scratch”import numpy as np
def pivot_columns(A, tol=1e-10):
"""Row-echelon form; returns the pivot column indices."""
M = A.astype(float).copy()
rows, cols = M.shape
piv, r = [], 0
for c in range(cols):
if r >= rows:
break
p = next((i for i in range(r, rows) if abs(M[i, c]) > tol), None)
if p is None:
continue
M[[r, p]] = M[[p, r]]
for i in range(r + 1, rows):
M[i] -= (M[i, c] / M[r, c]) * M[r]
piv.append(c)
r += 1
return piv, M
def basis_of_span(vectors):
"""The book's three-step recipe: columns, row-echelon form, pivot columns."""
A = np.array(vectors, dtype=float).T
piv, _ = pivot_columns(A)
return piv, [vectors[i] for i in piv]
# ---- the book's Example 2.17 -------------------------------------------
X = [[ 1.0, 2.0, -1.0, -1.0, -1.0],
[ 2.0, -1.0, 1.0, 2.0, -2.0],
[ 3.0, -4.0, 3.0, 5.0, -3.0],
[-1.0, 8.0, -5.0, -6.0, 1.0]]
piv, basis = basis_of_span(X)
print("pivot columns:", piv, " -> basis is x1, x2, x4")
print("dim(U):", len(piv))
# The book's claim: x3 is a combination of the others.
x1, x2, x3 = np.array(X[0]), np.array(X[1]), np.array(X[2])
print("x3 == -x1 + 2*x2 :", np.allclose(x3, -x1 + 2 * x2), " ", -x1 + 2 * x2)
# ---- the book's Example 2.18 ------------------------------------------
A1 = np.array([[1.0, 0.0, 1.0], [0.0, 1.0, 1.0], [0.0, 0.0, 0.0]])
A2 = np.array([[1.0, 2.0, 1.0], [-2.0, -3.0, 1.0], [3.0, 5.0, 0.0]])
print("\nExample 2.18 first rank:", np.linalg.matrix_rank(A1))
print("Example 2.18 second rank:", np.linalg.matrix_rank(A2),
" invertible:", np.linalg.matrix_rank(A2) == 3)
# ---- row rank equals column rank -------------------------------------
A = np.array([[1.0, 2.0, 3.0, 4.0],
[2.0, 4.0, 6.0, 8.0]])
print("\ncolumn rank:", np.linalg.matrix_rank(A))
print("row rank :", np.linalg.matrix_rank(A.T), " (same, always)")
# ---- the six properties, all six checked ------------------------------
m, n = A.shape
r = np.linalg.matrix_rank(A)
print("\nshape:", (m, n), " rank:", r)
print(" full rank? ", r == min(m, n))
print(" image dimension ", r, "(a line in R^2)")
print(" null-space dimension", n - r)
b_in = A @ np.array([1.0, 0.0, 0.0, 0.0]) # in the image by construction
b_out = np.array([1.0, 0.0]) # NOT a multiple of (1,2)
for name, b in (("b in the image", b_in), ("b outside", b_out)):
solvable = r == np.linalg.matrix_rank(np.c_[A, b])
print(f" {name:14s} solvable: {solvable}")
# ---- dimension is not the number of components -----------------------
V = np.array([[0.0, 1.0]]).T # span of a single vector in R^2
print("\nbasis vector has", V.shape[0], "components")
print("but dim(span) =", np.linalg.matrix_rank(V), "-> one-dimensional")
# ---- every basis of a space has the same size -------------------------
rng = np.random.default_rng(3)
print("\nsizes of ten random bases of R^4:", end=" ")
sizes = []
for _ in range(10):
B = rng.standard_normal((4, 4))
sizes.append(int(np.linalg.matrix_rank(B)))
print(sizes, " all equal:", len(set(sizes)) == 1)
# ---- uniqueness of coordinates ----------------------------------------
Bmat = np.array([[1.0, 1.0], [0.0, 1.0]]) # a basis of R^2
x = np.array([2.4, 1.6])
coords = np.linalg.solve(Bmat, x)
print("\ncoordinates of x in this basis:", coords)
print("rebuild:", Bmat @ coords, " == x:", np.allclose(Bmat @ coords, x))
# With a DEPENDENT set, coordinates stop being unique.
Dep = np.array([[1.0, 1.0, 2.0], [0.0, 1.0, 1.0]]) # three vectors in R^2
sol = np.linalg.lstsq(Dep, x, rcond=None)[0]
null = np.array([1.0, 1.0, -1.0]) # Dep @ null == 0
print("one solution :", np.round(sol, 4))
print("another :", np.round(sol + 5 * null, 4))
print("both rebuild x:", np.allclose(Dep @ sol, x), np.allclose(Dep @ (sol + 5 * null), x))pivot columns: [0, 1, 3] -> basis is x1, x2, x4
dim(U): 3
x3 == -x1 + 2*x2 : True [ 3. -4. 3. 5. -3.]
Example 2.18 first rank: 2
Example 2.18 second rank: 2 invertible: False
column rank: 1
row rank : 1 (same, always)
shape: (2, 4) rank: 1
full rank? False
image dimension 1 (a line in R^2)
null-space dimension 3
b in the image solvable: True
b outside solvable: False
basis vector has 2 components
but dim(span) = 1 -> one-dimensional
sizes of ten random bases of R^4: [4, 4, 4, 4, 4, 4, 4, 4, 4, 4] all equal: True
coordinates of x in this basis: [0.8 1.6]
rebuild: [2.4 1.6] == x: True
one solution : [-0. 0.8 0.8]
another : [ 5. 5.8 -4.2]
both rebuild x: True TrueThree readings.
Example 2.17 is confirmed exactly: pivot columns 1, 2 and 4, so , and reproduces to the digit.
The six properties all hold on one small rank-1 matrix. Note the solvability check: the same matrix is solvable for one right-hand side and not for another, decided purely by whether appending raises the rank.
The last block is characterisation 4, and its failure. With a genuine basis the coordinates are — one answer. With three vectors in the set still spans, so every point is still reachable, but two completely different coefficient vectors rebuild the same . Spanning survives redundancy; uniqueness does not. That is precisely what minimality buys.
On real data
Section titled “On real data”Reading the plot
Section titled “Reading the plot”The second figure is the bridge to Chapter 10, and it makes a point this section’s definitions cannot.
It plots the 8-by-8 handwritten digit images: 1797 of them, 64 pixels each. Two numbers matter.
The rank is 61, not 64. So rank does notice some exact dependence here — and what it noticed is dull: three border pixels are blank in every single image, so three columns are identically zero. That is what exact linear dependence usually looks like in real data. It is a data-collection artefact, not a structural insight.
Twenty-one components carry 90% of the variance, and twenty-nine carry 95%. That redundancy is the interesting kind, and rank is completely blind to it, because those remaining directions are small rather than zero. By the definitions on this page, all 61 surviving directions are equally independent.
So there are two different notions of dimension in play. The algebraic one, rank, is an integer and says 61. The effective one — how many directions matter — is not an integer at all, and depends on how much variance you are willing to discard: 21 at 90%, 29 at 95%.
That gap is the entire opportunity Chapter 10 exploits. PCA does not look for a rank deficiency; it looks for where the spectrum falls off and truncates there. §4.6’s Eckart–Young theorem then says the truncation is the best possible low-rank approximation.
Pitfalls
Section titled “Pitfalls”Compare
Section titled “Compare”| concept | question it answers | is it unique? |
|---|---|---|
| span | what can these vectors reach? | yes — a specific subspace |
| generating set | do they reach everything? | no — many exist, of many sizes |
| basis | the smallest set that reaches everything | no — many bases exist |
| dimension | how many vectors does any basis have? | yes |
| rank | how many independent directions does a matrix carry? | yes |
| condition number | how close to dependent are they? | yes, and it is the practical question |
-
Which of these is NOT one of the four equivalent characterisations of a basis?
Orthogonality is a much stronger extra condition — it makes an ORTHONORMAL basis, which is section 3.5's subject and genuinely more convenient. Plenty of perfectly good bases are not orthogonal.
pch.quizShowAnswer
D — A set whose vectors are mutually orthogonal — Orthogonality is a much stronger extra condition — it makes an ORTHONORMAL basis, which is section 3.5's subject and genuinely more convenient. Plenty of perfectly good bases are not orthogonal.
-
The span of a single two-component vector is what dimension?
Dimension counts independent directions, not entries. The book gives exactly this example as a warning. A line in a thousand-dimensional space is still one-dimensional.
pch.quizShowAnswer
B — One — Dimension counts independent directions, not entries. The book gives exactly this example as a warning. A line in a thousand-dimensional space is still one-dimensional.
-
A matrix is two-by-four with rank 2. What is the dimension of its null space?
The null-space dimension is n minus the rank, where n is the number of columns. Four minus two is two. Note this matrix also has full rank, since the maximum possible for its shape is two — and it still has no inverse.
pch.quizShowAnswer
B — Two — The null-space dimension is n minus the rank, where n is the number of columns. Four minus two is two. Note this matrix also has full rank, since the maximum possible for its shape is two — and it still has no inverse.
-
Two features in a dataset are 99.99 percent collinear. What does the rank tell you?
Rank answers 'exactly zero?' and the answer is no. Near dependence shows up as a tiny singular value and a huge condition number, which is why regularisation exists rather than a rank check.
pch.quizShowAnswer
B — Nothing useful — the rank is still full, because the dependence is not exact. The condition number is the diagnostic — Rank answers 'exactly zero?' and the answer is no. Near dependence shows up as a tiny singular value and a huge condition number, which is why regularisation exists rather than a rank check.
🧪 Try It Yourself
Section titled “🧪 Try It Yourself”Exercise 1 – Extract a basis from a spanning set
Section titled “Exercise 1 – Extract a basis from a spanning set”Exercise 2 – Row rank equals column rank
Section titled “Exercise 2 – Row rank equals column rank”Exercise 3 – The null-space dimension
Section titled “Exercise 3 – The null-space dimension”Exercise 4 – Uniqueness is what minimality buys
Section titled “Exercise 4 – Uniqueness is what minimality buys”Exercise 5 – Rank is blind to near-dependence
Section titled “Exercise 5 – Rank is blind to near-dependence”Recall card
Section titled “Recall card”- The span of a set is every linear combination of it, and a span is always a subspace — which is how subspaces are manufactured.
- A generating set reaches everything; a basis is a generating set that is also minimal, equivalently linearly independent.
- Four equivalent characterisations of a basis — basis, minimal generating set, maximal independent set, and unique representation of every vector.
- A basis is squeezed from both sides: minimal among spanning sets and maximal among independent sets simultaneously.
- Uniqueness of coordinates IS linear independence rewritten — subtract two representations and independence forces the difference to vanish.
- No basis is unique but every basis of a space has the same size, and that invariant number is the dimension.
- Dimension counts independent directions, not components — a line in a thousand-dimensional space is one-dimensional.
- A basis of a subspace comes from three steps: spanning vectors as columns, row-echelon form, keep the pivot columns.
- Row rank equals column rank, always — two counts about vectors in different spaces that never disagree.
- Rank decides invertibility, solvability, image dimension and null-space dimension — the null space has dimension minus the rank.
- Full rank is not the same as invertible: full rank means the most its shape allows, and a non-square matrix can never be inverted.
- Rank is blind to near-dependence. It answers “exactly zero?”; the practical question is “how small?”, answered by the singular values and the condition number.
Next: functions that are secretly matrices — Linear Mappings.
pch.coffeeTagline
pch.coffeeCtapch.feedbackHeading
pch.feedbackSubheading