15–18 min read Linear Algebra & Data Science Lesson 19 of 32
Part 3 — Linear Algebra (Lesson 6)

Lesson 14.19 — Basis, Dimension & Rank

How do we measure the true internal complexity and degrees of freedom of a vector space? When working with a dataset of 100 features, are all 100 truly providing independent information, or is there massive hidden redundancy? What is the minimal coordinate skeleton required to navigate any space without ambiguity? In this lesson, we master the fundamental trinity of linear algebra: Basis, Dimension, and Matrix Rank—the conceptual bedrock powering PCA, data compression, and modern deep learning.

1 Introduction: Understanding Vector Space Architecture

In the previous lesson, we learned how to solve systems of linear equations using Gaussian elimination and matrix equations $A\mathbf{x} = \mathbf{b}$. However, when scaling up to high-dimensional datasets in computer science, robotics, and machine learning, deeper structural questions emerge:

  • • Redundancy: Given a collection of vectors, can some of them be synthesized entirely as combinations of the others?
  • • Information Content: Does every column or feature in a dataset contribute genuinely distinct, non-overlapping information?
  • • Minimal Basis: What is the smallest set of independent coordinate axes required to span the entire space without gaps or excess?

Linear algebra answers these questions through three deeply intertwined concepts:

1. Basis

The minimal generating set of linearly independent vectors needed to span a vector space without redundancy.

2. Dimension

The number of vectors in any basis of the space, representing its intrinsic degrees of freedom.

3. Rank

The maximal number of linearly independent row or column vectors in a matrix.

2 Linear Combinations and Span

Before formalizing basis and dimension, we must firmly establish two foundational building blocks: Linear Combinations and Span.

Linear Combinations

Multiplying a collection of vectors by scalar constants and adding the results produces a Linear Combination.

Consider two 2D vectors:

$$\mathbf{u} = \begin{bmatrix} 1 \\ 2 \end{bmatrix}, \quad \mathbf{v} = \begin{bmatrix} 3 \\ 1 \end{bmatrix}$$

Scaling $\mathbf{u}$ by 2 and $\mathbf{v}$ by 3 yields:

$$2\mathbf{u} + 3\mathbf{v} = 2\begin{bmatrix} 1 \\ 2 \end{bmatrix} + 3\begin{bmatrix} 3 \\ 1 \end{bmatrix} = \begin{bmatrix} 2 \\ 4 \end{bmatrix} + \begin{bmatrix} 9 \\ 3 \end{bmatrix} = \begin{bmatrix} 11 \\ 7 \end{bmatrix}$$

The vector $\begin{bmatrix} 11 \\ 7 \end{bmatrix}$ is a linear combination of $\mathbf{u}$ and $\mathbf{v}$. More generally, for $k$ vectors, any linear combination takes the form $\sum_{i=1}^k c_i \mathbf{v}_i$ where $c_i \in \mathbb{R}$.

Span (The Reach of a Vector Set)

The collection of all possible linear combinations that can be synthesized from a set of vectors forms their Span:

$$\operatorname{Span}(\mathbf{v}_1, \dots, \mathbf{v}_k) = \left\{ \sum_{i=1}^k c_i \mathbf{v}_i \;\middle|\; c_i \in \mathbb{R} \right\}$$
Span of 1 Non-Zero Vector: Let $\mathbf{u} = \begin{bmatrix} 1 \\ 0 \end{bmatrix}$. Scaling $\mathbf{u}$ by any scalar $a$ gives $\begin{bmatrix} a \\ 0 \end{bmatrix}$. This spans an infinite 1D straight line along the $x$-axis.
Span of 2 Non-Collinear Vectors: Let $\mathbf{u} = \begin{bmatrix} 1 \\ 0 \end{bmatrix}$ and $\mathbf{v} = \begin{bmatrix} 0 \\ 1 \end{bmatrix}$. Any linear combination $a\mathbf{u} + b\mathbf{v} = \begin{bmatrix} a \\ b \end{bmatrix}$ covers every point, spanning the entire 2D plane $\mathbb{R}^2$.

3 Linear Independence vs. Linear Dependence

Does every vector in a set contribute a genuine new direction, or are some redundant? This is measured via Linear Independence.

Formal Definition

A set of vectors $\{\mathbf{v}_1, \mathbf{v}_2, \dots, \mathbf{v}_n\}$ is Linearly Independent if the equation:

$$c_1 \mathbf{v}_1 + c_2 \mathbf{v}_2 + \dots + c_n \mathbf{v}_n = \mathbf{0}$$

has only the trivial solution: $c_1 = c_2 = \dots = c_n = 0$. If there exists any non-trivial solution (where at least one $c_i \ne 0$), the set is Linearly Dependent.

Linearly Independent

$\mathbf{u} = \begin{bmatrix} 1 \\ 0 \end{bmatrix}, \mathbf{v} = \begin{bmatrix} 0 \\ 1 \end{bmatrix}$
$c_1 \begin{bmatrix} 1 \\ 0 \end{bmatrix} + c_2 \begin{bmatrix} 0 \\ 1 \end{bmatrix} = \begin{bmatrix} 0 \\ 0 \end{bmatrix} \implies c_1 = 0, c_2 = 0$

Neither vector can be expressed in terms of the other. Both contribute unique spatial directions.

Linearly Dependent

$\mathbf{u} = \begin{bmatrix} 1 \\ 2 \end{bmatrix}, \mathbf{v} = \begin{bmatrix} 2 \\ 4 \end{bmatrix}$
Notice: $\mathbf{v} = 2\mathbf{u} \implies 2\mathbf{u} - \mathbf{v} = \mathbf{0}$

Here $c_1 = 2, c_2 = -1 \ne 0$. Vector $\mathbf{v}$ adds no new direction beyond what $\mathbf{u}$ already provides.

4 Basis: The Minimal Generating Coordinate Skeleton

A Basis $\mathcal{B} = \{\mathbf{v}_1, \dots, \mathbf{v}_k\}$ for a vector space $V$ is a set of vectors that simultaneously satisfies two strict criteria:

1
No Redundancy (Linearly Independent): No vector in $\mathcal{B}$ can be constructed from any combination of the other vectors in $\mathcal{B}$.
2
No Omissions (Spans the Entire Space): Every single vector in space $V$ can be represented as a linear combination of vectors in $\mathcal{B}$ ($\operatorname{Span}(\mathcal{B}) = V$).

The Standard Basis

In Cartesian space $\mathbb{R}^2$, the canonical Standard Basis consists of the elementary coordinate unit vectors:

$$\mathbf{e}_1 = \begin{bmatrix} 1 \\ 0 \end{bmatrix}, \quad \mathbf{e}_2 = \begin{bmatrix} 0 \\ 1 \end{bmatrix}$$

Any vector $\begin{bmatrix} a \\ b \end{bmatrix}$ is expressed uniquely as $a\mathbf{e}_1 + b\mathbf{e}_2$. In $\mathbb{R}^3$, the standard basis consists of $\mathbf{e}_1 = (1, 0, 0), \mathbf{e}_2 = (0, 1, 0), \mathbf{e}_3 = (0, 0, 1)$.

The Golden Invariance Rule: A vector space has infinitely many distinct bases! For instance, $\mathbf{u} = \begin{bmatrix} 1 \\ 1 \end{bmatrix}$ and $\mathbf{v} = \begin{bmatrix} 1 \\ -1 \end{bmatrix}$ form an equally valid basis for $\mathbb{R}^2$. However, all bases for a given space share an invariant law: every basis contains the exact same number of vectors!

5 Dimension: Degrees of Freedom in a Vector Space

Definition of Dimension

The Dimension of a vector space $V$ is defined as the number of vectors in any of its bases: $$\dim(V) = |\mathcal{B}|$$

Geometric Space / Subspace Number of Basis Vectors Dimension ($\dim$)
Origin Point ($\{\mathbf{0}\}$) 0 0
Line through origin 1 1
Plane through origin 2 2
Full 3D Euclidean Space ($\mathbb{R}^3$) 3 3
$n$-Dimensional Real Space ($\mathbb{R}^n$) $n$ $n$

Ambient Dimension vs. Intrinsic Dimension: In machine learning, a dataset with 100 features resides in 100-dimensional ambient space. However, if strong correlations exist, the data points may actually lie on a 5-dimensional hyperplane or manifold. The true intrinsic dimension of the data is 5, not 100.

6 Matrix Rank: Quantifying Non-Redundant Information

The Rank of a matrix is the maximum number of linearly independent column vectors (Column Rank) or row vectors (Row Rank) it contains.

Fundamental Theorem of Rank:

For any rectangular or square matrix $A \in \mathbb{R}^{m \times n}$, the Row Rank equals the Column Rank: $$\operatorname{Rank}(A) = \dim(\operatorname{Col}(A)) = \dim(\operatorname{Row}(A))$$ The rank is bounded by the smallest dimension: $0 \le \operatorname{Rank}(A) \le \min(m, n)$.

Computing Rank via Gaussian Elimination

To determine matrix rank, perform elementary row operations until the matrix is in Row Echelon Form (REF). The number of non-zero rows (or pivot positions) equals the rank:

$$A = \begin{bmatrix} 1 & 2 & 3 \\ 2 & 4 & 6 \\ 1 & 1 & 1 \end{bmatrix}$$

Step 1: Eliminate beneath the first pivot ($R_2 \leftarrow R_2 - 2R_1$ and $R_3 \leftarrow R_3 - R_1$):

$$\begin{bmatrix} 1 & 2 & 3 \\ 0 & 0 & 0 \\ 0 & -1 & -2 \end{bmatrix}$$

Step 2: Swap Rows 2 and 3 ($R_2 \leftrightarrow R_3$) to bring non-zero rows to the top:

$$\begin{bmatrix} 1 & 2 & 3 \\ 0 & -1 & -2 \\ 0 & 0 & 0 \end{bmatrix} \quad \text{(Row Echelon Form)}$$
Number of Non-Zero Rows / Pivots = 2 $\implies \mathbf{\operatorname{Rank}(A) = 2}$

Despite having 3 rows and 3 columns, the matrix collapses 3D space into a 2D plane. Column 3 is a linear combination of Columns 1 and 2: $\mathbf{col}_3 = -\mathbf{col}_1 + 2\mathbf{col}_2$.

7 The Four Fundamental Subspaces & Rank-Nullity

Every $m \times n$ matrix $A$ defines four fundamental subspaces that partition vector spaces $\mathbb{R}^n$ and $\mathbb{R}^m$:

1. Column Space $\operatorname{Col}(A)$: Span of columns of $A$. Dimension = $\operatorname{Rank}(A) = r$. Subspace of $\mathbb{R}^m$.
2. Row Space $\operatorname{Row}(A)$: Span of rows of $A$. Dimension = $\operatorname{Rank}(A) = r$. Subspace of $\mathbb{R}^n$.
3. Null Space $\operatorname{Null}(A)$: Solutions to $A\mathbf{x} = \mathbf{0}$. Dimension = $n - r$ (Nullity). Subspace of $\mathbb{R}^n$.
4. Left Null Space $\operatorname{Null}(A^T)$: Solutions to $A^T \mathbf{y} = \mathbf{0}$. Dimension = $m - r$. Subspace of $\mathbb{R}^m$.

The Rank-Nullity Theorem

$$\operatorname{Rank}(A) + \operatorname{Nullity}(A) = n$$

Total input dimensions ($n$) = output dimensions preserved ($r$) + input dimensions collapsed to zero ($n - r$).

8 Using Rank to Diagnose Linear Systems (Rouché–Capelli)

We can now formally classify any linear system $A\mathbf{x} = \mathbf{b}$ by comparing the rank of $A$ with the rank of augmented matrix $[A \mid \mathbf{b}]$:

1. Unique Solution $\operatorname{Rank}(A) = \operatorname{Rank}([A \mid \mathbf{b}]) = n$

Full column rank. Vector $\mathbf{b}$ lies within the column space, and no free variables exist.

2. Infinitely Many Solutions $\operatorname{Rank}(A) = \operatorname{Rank}([A \mid \mathbf{b}]) < n$

Consistent system, but fewer pivots than variables. Exactly $n - r$ free variables parametrize the solution manifold.

3. No Solution $\operatorname{Rank}(A) < \operatorname{Rank}([A \mid \mathbf{b}])$

Inconsistent system. The target vector $\mathbf{b}$ lies entirely outside the column space $\operatorname{Col}(A)$.

9 Computing Rank and Subspaces in Python

In computational code, `np.linalg.matrix_rank` calculates rank via Singular Value Decomposition (SVD), automatically handling numerical tolerances:

import numpy as np
from scipy.linalg import null_space

# Define 3x3 matrix
A = np.array([
    [1, 2, 3],
    [2, 4, 6],
    [1, 1, 1]
], dtype=float)

# 1. Compute Matrix Rank
r = np.linalg.matrix_rank(A)
print("Rank of A:", r)  # Output: 2

# 2. Compute Null Space Basis
ns = null_space(A)
print("Null Space Basis:\n", ns)
nullity = ns.shape[1]
print("Nullity:", nullity)  # Output: 1

# 3. Verify Rank-Nullity Theorem (n = 3)
print("Rank + Nullity == n:", r + nullity == A.shape[1])  # True (2 + 1 = 3)

10 Real-World Applications in Computer Science & AI

Rank and dimension analysis govern the compression and efficiency of modern machine learning systems:

1. Principal Component Analysis (PCA)

PCA finds the orthonormal basis along directions of maximum variance in high-dimensional datasets, discarding noisy or redundant dimensions to reduce storage and training time.

2. Low-Rank Image Compression

Digital images are 2D pixel matrices. Low-rank matrix approximations (via Truncated SVD) reconstruct the image using a handful of singular vectors, preserving 90%+ perceptual fidelity at a fraction of file size.

3. Recommender Systems (Netflix Prize)

Massive user-movie rating matrices have billions of entries but are modeled as low-rank matrices ($R \approx U V^T$), recovering hidden user preference factors.

4. Multicollinearity Detection

When dataset features are linearly dependent, $X^T X$ becomes singular (rank-deficient), breaking Ordinary Least Squares. Rank diagnostics indicate when feature elimination or regularization (L2) is required.

11 8 Common Pitfalls & Traps

Pitfall 1: Confusing Span with Basis

The Span is the entire infinite vector space generated. The Basis is the minimal set of independent vectors used to generate it.

Pitfall 2: Assuming a Unique Basis

Every vector space possesses infinitely many distinct bases. Only the number of vectors (the dimension) is unique.

Pitfall 3: Picking Columns from the REF

When writing a basis for $\operatorname{Col}(A)$, locate pivot columns in the Row Echelon Form, but choose the corresponding columns from the ORIGINAL matrix!

Pitfall 4: Including $\mathbf{0}$ in a Basis

A basis can never contain the zero vector. Including $\mathbf{0}$ immediately renders the set linearly dependent ($1 \cdot \mathbf{0} = \mathbf{0}$).

Pitfall 5: Ambient Dimension vs. Matrix Rank

A $3 \times 3$ matrix lives in $\mathbb{R}^3$, but its rank can be 1 or 2 if rows/columns are redundant.

Pitfall 6: Assuming Row Rank $\ne$ Column Rank

Even for highly non-square rectangular matrices, Row Rank and Column Rank are always identical.

Pitfall 7: More Vectors $\implies$ More Dimensions

Supplying 4 vectors in $\mathbb{R}^2$ cannot create 4 dimensions; they are guaranteed to be dependent, and the dimension remains 2.

Pitfall 8: Exact Zero Checking in Floating-Point Code

Roundoff noise in computers creates tiny non-zero floats (e.g. `1e-17`). Always use a tolerance threshold when checking rank.

Interactive Hands-on Lab

Basis, Dimension & Rank Workbench

Experiment live with vector independence, matrix rank reduction, and PCA projection.

Vector 1 ($\mathbf{u}$): Blue
Vector 2 ($\mathbf{v}$): Green
Parallelogram Area ($\det$): 3.00
Independence Status: Linearly Independent
Span Dimension: Dimension 2 (Full R^2)
Vector u Vector v Span Region

Key Takeaways

1. Linear Combination

Synthesizing new vectors by scaling and summing existing vectors.

2. Span

The complete subspace formed by all possible linear combinations of a vector set.

3. Linear Independence

No vector in the set can be expressed as a linear combination of the remaining vectors.

4. Basis

The minimal linearly independent generating set that spans the entire vector space.

5. Dimension

The invariant number of basis vectors required to navigate a vector space.

6. Matrix Rank

The number of independent rows or columns; equals the number of pivots in Row Echelon Form.

7. Rank-Nullity Theorem

Total columns ($n$) = Output rank dimension ($r$) + Null space collapsed dimension ($n - r$).

8. Solvability Criteria

A linear system is consistent if and only if $\operatorname{Rank}(A) = \operatorname{Rank}([A \mid \mathbf{b}])$.

9. PCA & Compression

Low-rank matrix approximations compress data and remove noise along principal basis directions.