Search

Search papers and lessons

Matrix Rank

Level 2 · 9 min read

The rank of a matrix counts how many of its rows or columns are truly independent, which is the number of directions its outputs can reach.

On this page

  • Colour = topic mix
  • Linear algebra
  • Discrete math
  • Sign in to see your progress

TL;DR

A matrix can look like a large table of numbers, but many of its rows or columns may repeat information the others already carry. The rank counts how much genuinely new information it holds: the largest number of columns that are linearly independent. Equivalently, it is the number of dimensions of output space the matrix can reach.

Where you'll see it: deciding whether a system of linear equations has a solution, and in LoRA, where a fine-tuning update is forced to have low rank so that it stores far fewer numbers.

Intuition

Repeated information

Take a price list with three columns: price in dollars, price in euros, and the number of items. Suppose the euro column is always the dollar column times 0.9. The table has three columns, but only two of them carry new information, because the euro column can be computed from the dollar column. Rank is the count of what is really there.

The tool for this is linear independence. A set of vectors is independent when none of them can be built from the others. The rank of a matrix is the largest number of its columns that form an independent set. In the price list, the euro column is a multiple of the dollar column, so the two are dependent and the rank is 2.

Rank as reach

Apply the matrix as a machine, y=Ax\mathbf{y} = A\mathbf{x}, and ask which outputs are possible. If every column of AA is a multiple of one vector, every output lies on one line through the origin: the matrix reaches only one direction. If the columns span a plane, the outputs fill the plane. Rank is the dimension of the set of reachable outputs, which is the number of directions the linear transformation keeps alive.

flowchart LR
  A[Matrix A with n columns] --> B[Find the independent columns]
  B --> C[Count them: this is the rank]
  C --> D[Outputs fill a space of that dimension]
  C --> E[Inputs sent to zero: n minus rank]

Why it exists

Gaussian elimination is the classical way to solve a system Ax=bA\mathbf{x} = \mathbf{b}. Running it tells you whether a solution exists at all. The number of pivots it finds, meaning rows that still have a nonzero leading entry after elimination, is the rank. Rank summarises the outcome of the whole procedure in one integer, which is why it matters in theory and in software.

The math

Definition

Definition: Rank

The rank of a matrix AA with mm rows and nn columns, written rank⁡(A)\operatorname{rank}(A), is the maximum number of linearly independent columns of AA. Equivalently, it is the dimension of the column space of AA, the set of all vectors of the form AxA\mathbf{x}.

Each column of AA is a vector in Rm\mathbb{R}^m. The rank is how many of those columns you need as a building set: every column is a combination of the independent ones, and no fewer will do.

Key results

Rank is at most the smaller dimension.

rank⁡(A)≤min⁡(m,n)\operatorname{rank}(A) \le \min(m, n)

A table with 1000 rows and 3 columns has rank at most 3. When the rank equals min⁡(m,n)\min(m, n) the matrix is called full rank.

Row rank equals column rank.

rank⁡(A⊤)=rank⁡(A)\operatorname{rank}(A^\top) = \operatorname{rank}(A)

The number of independent rows is the same as the number of independent columns, so there is one well-defined rank.

Rank-nullity. The null space ker⁡(A)\ker(A) is the set of inputs sent to zero. Its dimension is the nullity.

rank⁡(A)+dim⁡ker⁡(A)=n\operatorname{rank}(A) + \dim\ker(A) = n

Each column that depends on earlier columns produces one direction that AA sends to zero. The nn columns split into independent ones (counted by the rank) and dependent ones (each giving a null direction).

Products cannot increase rank.

rank⁡(AB)≤min⁡(rank⁡(A),rank⁡(B))\operatorname{rank}(AB) \le \min\big(\operatorname{rank}(A), \operatorname{rank}(B)\big)

Every column of ABAB is a combination of columns of AA, so its columns all lie in the column space of AA. Multiplying can only lose information. This is why multiplying matrices cannot make a rank-deficient matrix full rank.

Rank-rr factorisation. If rank⁡(A)=r\operatorname{rank}(A) = r, then AA can be written as a product of two thin matrices:

A=UV⊤,U∈Rm×r,V∈Rn×r.A = UV^\top, \qquad U \in \mathbb{R}^{m \times r}, \qquad V \in \mathbb{R}^{n \times r}.

To see why, pick rr independent columns of AA and place them in UU. Every other column aj\mathbf{a}_j of AA lies in their span, so aj=Uvj\mathbf{a}_j = U\mathbf{v}_j for some coefficient vector vj∈Rr\mathbf{v}_j \in \mathbb{R}^r. Stack the vj\mathbf{v}_j as the rows of VV and the product UV⊤UV^\top reproduces every column of AA. Storing UU and VV takes r(m+n)r(m + n) numbers instead of mnmn. This is the fact that LoRA exploits.

02040608010000.050.10.150.2rank rstored numbers / full size
  • r(m + n) / (m n), with m = n = 1000
For a 1000 by 1000 matrix, a rank-r factorisation stores 2r/1000 of the entries. At rank 4 that is 0.8 percent.

Worked examples

Example
A rank-one table

Let B=(1236)B = \begin{pmatrix} 1 & 2 \\ 3 & 6 \end{pmatrix}.

  1. Column 1 is (1,3)(1, 3) and column 2 is (2,6)(2, 6), so column 2 equals 22 times column 1.
  2. The columns are dependent, so the largest independent set has one column. The rank is 1.
  3. Row reduction agrees. Subtract 3 times row 1 from row 2 to get (0,0)(0, 0). One pivot remains.
  4. Factor it as B=UV⊤B = UV^\top with U=(1,3)⊤U = (1, 3)^\top and V=(1,2)⊤V = (1, 2)^\top. Then UV⊤=(1236)=BUV^\top = \begin{pmatrix} 1 & 2 \\ 3 & 6 \end{pmatrix} = B.

Interpretation: every output of BB lies on the line through (1,3)(1, 3). Only one direction is reachable, so the rank is 1.

Example
A three-by-three matrix with a null direction

Let M=(121240361)M = \begin{pmatrix} 1 & 2 & 1 \\ 2 & 4 & 0 \\ 3 & 6 & 1 \end{pmatrix}.

  1. Subtract 2 times row 1 from row 2. The result is (0,0,−2)(0, 0, -2).
  2. Subtract 3 times row 1 from row 3. The result is (0,0,−2)(0, 0, -2).
  3. Subtract the new row 2 from the new row 3. The result is (0,0,0)(0, 0, 0).
  4. Two pivots remain, in columns 1 and 3, so rank⁡(M)=2\operatorname{rank}(M) = 2.
  5. Rank-nullity gives dim⁡ker⁡(M)=3−2=1\dim\ker(M) = 3 - 2 = 1. The vector (−2,1,0)(-2, 1, 0) is sent to zero. Row 1 gives −2+2+0=0-2 + 2 + 0 = 0, row 2 gives −4+4+0=0-4 + 4 + 0 = 0, and row 3 gives −6+6+0=0-6 + 6 + 0 = 0.

Interpretation: outputs of MM fill only a plane in three-dimensional space, so some right-hand sides b\mathbf{b} can never be reached. The matrix also flattens one direction completely.

Example
Rank in a LoRA update

A fine-tuning update to one 1000×10001000 \times 1000 weight matrix has 10610^6 entries. LoRA forces the update to have rank r=4r = 4, so it is stored as UU (size 1000×41000 \times 4) times V⊤V^\top (size 4×10004 \times 1000).

  1. Entries in UU: 1000×4=40001000 \times 4 = 4000.
  2. Entries in VV: 1000×4=40001000 \times 4 = 4000.
  3. Total stored: 80008000.
  4. Fraction stored: 8000/106=0.0088000 / 10^6 = 0.008, or 0.8 percent.

Interpretation: the update is restricted to a rank-4 family of changes and costs under one percent of the storage. Choosing rr is a trade between what the update can express and what it costs.

Tradeoffs and failure modes

Rank is an exact idea, but computers work with rounded floating-point numbers. Exact zeros almost never appear, so software decides rank with a tolerance: compute the singular values with the SVD and count the ones above a threshold.

SituationWhat goes wrongBetter choice
Noisy measured dataExact rank is almost always full, so noise hides the structureCount singular values above a tolerance
You need the solutions of Ax=bA\mathbf{x} = \mathbf{b}Rank says whether a solution exists, not what it isRow reduce and read off pivots and free variables
Compressing a dense weight matrixA full-rank matrix cannot be stored in fewer numbers without lossTruncated SVD. The Eckart-Young theorem says it gives the best rank-rr approximation
Choosing a LoRA rankA rank that is too small limits what the update can learnTry several values of rr and compare on validation data

Rank applies to linear maps. A nonlinear function has no single rank, but its Jacobian matrix has a rank at each point, and that local rank is often the useful quantity.

History

Carl Friedrich Gauss used the method of elimination in the early 1800s for least-squares calculations in astronomy. The procedure existed long before anyone called the result a rank. In the late 1870s, Ferdinand Georg Frobenius gave the precise definition of the rank of a matrix while studying systems of equations and bilinear forms.

Rank caught on because it reduces many questions about linear systems to one integer. Computers made elimination and the SVD routine, so the number became cheap to compute. In 2021 the LoRA paper by Hu and colleagues made rank a design knob for large neural networks, which brought the idea into machine learning practice.

Check yourself

QuestionWhat is the rank of the 3 by 3 identity matrix?Show answer

The identity has three columns, and they are the standard basis vectors (1,0,0)(1,0,0), (0,1,0)(0,1,0) and (0,0,1)(0,0,1). None of them can be built from the others, so all three are independent. The rank is 3, which is full rank.

QuestionA 2 by 2 matrix has rows (2, 4) and (1, 2). What are its rank and nullity?Show answer

Column 2 is (4,2)(4, 2), which equals 22 times column 1 (2,1)(2, 1). The columns are dependent, so the rank is 1. Rank-nullity gives nullity 2−1=12 - 1 = 1. The null vector is (−2,1)(-2, 1): the first row gives 2(−2)+4(1)=02(-2) + 4(1) = 0 and the second gives 1(−2)+2(1)=01(-2) + 2(1) = 0.

QuestionWhy can the rank of a product AB never exceed the rank of A?Show answer

Each column of ABAB is AA applied to a column of BB, which is a linear combination of the columns of AA. So every column of ABAB lies in the column space of AA. That space has dimension rank⁡(A)\operatorname{rank}(A), so ABAB cannot have more independent columns than that.

QuestionA 512 by 512 weight matrix gets a LoRA update of rank 8. What fraction of its entries does the update store?Show answer

The factored form stores 2×512×8=81922 \times 512 \times 8 = 8192 numbers. The full matrix has 5122=262144512^2 = 262144 entries. The fraction is 8192/262144=0.031258192 / 262144 = 0.03125, or 3.125 percent.

Sources