Prerequisite · Linear Algebra

Dimension

14 min read
By the end of this reading you will be able to:
  • Explain why any two bases of the same finite-dimensional space have the same number of vectors (Dimension Theorem)
  • Compute the rank and nullity of a matrix and verify that they sum to the number of columns
  • Use dimension counting as a shortcut to confirm that a set spans or is independent without row reduction
  • Interpret rank as the number of independent directions in a matrix and relate it to information capacity in ML models

All Bases Have the Same Size

The most surprising and important fact about bases is:

Theorem (Invariance of Dimension): any two bases for the same vector space VV have the same number of elements.

This number is the dimension of VV, written dim(V)\dim(V). It is well-defined regardless of which basis you choose.

Proof sketch: if B1B_1 has mm vectors and B2B_2 has nn vectors and both are bases, then expressing each B1B_1 vector in terms of B2B_2 and using a linear-algebra counting argument shows mnm \leq n. Repeating with the roles swapped gives nmn \leq m, so m=nm = n.

Dimensions of Common Spaces

Space Dimension Natural basis
Rn\mathbb{R}^n nn {e1,,en}\{\vec{e}_1,\ldots,\vec{e}_n\}
Mm×n\mathcal{M}_{m\times n} mnmn matrix units EijE_{ij}
Pn\mathcal{P}_n (deg n\leq n) n+1n+1 {1,x,x2,,xn}\{1, x, x^2, \ldots, x^n\}
{0}\{\vec{0}\} 00 empty set
R\mathbb{R}^\infty (sequences) \infty

Using Dimension to Identify Bases

In a space of dimension nn, any set of exactly nn vectors that satisfies one of the following automatically satisfies both:

  • nn independent vectors → automatically span VV → basis
  • nn spanning vectors → automatically independent → basis

This is immensely practical: to show a set of nn vectors is a basis for Rn\mathbb{R}^n, you only need to check independence (or spanning) — the other condition is free.

The Rank-Nullity Theorem

For any m×nm \times n matrix AA, define:

  • rank(A)\text{rank}(A) = dimension of the column space C(A)\mathcal{C}(A) = number of pivots in echelon form
  • nullity(A)\text{nullity}(A) = dimension of the null space N(A)\mathcal{N}(A) = number of free variables

Then:

rank(A)+nullity(A)=n\text{rank}(A) + \text{nullity}(A) = n

Every column of AA is either a pivot column (contributing to rank) or a free column (contributing to nullity). The two types partition all nn columns.

Equivalences for an n×nn \times n matrix AA:

All of the following are equivalent:

  • rank(A)=n\text{rank}(A) = n
  • nullity(A)=0\text{nullity}(A) = 0, i.e., N(A)={0}\mathcal{N}(A) = \{\vec{0}\}
  • The columns of AA are linearly independent
  • The columns of AA span Rn\mathbb{R}^n
  • AA is invertible
  • det(A)eq0\det(A) eq 0
  • Ax=bA\vec{x} = \vec{b} has a unique solution for every b\vec{b}

This list of equivalences is sometimes called the Invertible Matrix Theorem. Knowing any one of them gives all the others for free.

Dimension of Subspaces

If WW is a subspace of VV with dim(V)=n\dim(V) = n:

  • dim(W)n\dim(W) \leq n
  • dim(W)=n    W=V\dim(W) = n \iff W = V (the only nn-dimensional subspace of VV is VV itself)
  • dim(W)=0    W={0}\dim(W) = 0 \iff W = \{\vec{0}\}

Combining Subspaces

If V=W1+W2V = W_1 + W_2 (every vector in VV is a sum of a vector from W1W_1 and one from W2W_2), the dimension formula is:

dim(W1+W2)=dim(W1)+dim(W2)dim(W1W2)\dim(W_1 + W_2) = \dim(W_1) + \dim(W_2) - \dim(W_1 \cap W_2)

If the intersection is only {0}\{\vec{0}\}, the sum is direct: V=W1W2V = W_1 \oplus W_2 and dim(V)=dim(W1)+dim(W2)\dim(V) = \dim(W_1) + \dim(W_2). The direct sum decomposes VV into orthogonal (or at least non-overlapping) pieces — the matrix analogue is block-diagonal decomposition.

Computing Rank and Nullity

import numpy as np

# 2 × 4 matrix — rank 2, nullity 2
A = np.array([[1., 2., 0., 1.],
              [2., 4., 1., 1.]])

# Rank and nullity via SVD
_, S, Vh = np.linalg.svd(A, full_matrices=True)
rank    = int(np.sum(S > 1e-9))
nullity = A.shape[1] - rank

print(f'rank    = {rank}')                                       # 2
print(f'nullity = {nullity}')                                    # 2
print(f'rank + nullity = {rank + nullity} = n = {A.shape[1]}')  # 2 + 2 = 4

# Null space basis: rows of Vh beyond rank index
null_basis = Vh[rank:]
print('null space basis (rows):')
print(np.round(null_basis, 4))

# Verify A @ null_vec = 0 for every null vector
for i, h in enumerate(null_basis):
    resid = np.einsum('ij,j->i', A, h)
    print(f'A @ null_basis[{i}] = {np.round(resid, 4)}')  # [0. 0.]

The row dimension of Vh[rank:] always equals the nullity — that is the Rank-Nullity Theorem made concrete. For a square invertible matrix, rank == n, so Vh[rank:] is empty and nullity == 0.

References
Hefferon 2020 — Linear Algebra, Ch. Two §III: Basis and Dimension