Level 3 In-Depth AI · Math Foundations
Eigenvectors and SVD
Eigenvectors are the directions a matrix only stretches. The singular value decomposition breaks any matrix into rotate, stretch, rotate, and shows how to approximate a huge matrix with two thin ones. This is the maths behind PCA, recommenders and LoRA.
- Level
- ●●●●● Intermediate
- Reading
- 12 min
- To learn it well
- 1 hour to read, an afternoon to practise
- Builds on
- 2 concepts →
- Quiz
- 5 questions ↓
Read first
Matrices and Matrix MultiplicationThe full path from zero — 2 concepts before this one
- Vectors
- Matrices and Matrix Multiplication
- Eigenvectors and SVD
Read them roughly in this order. See it on the concept map →
Why it matters
A matrix can be a big, opaque block of numbers. A weight matrix in a language model may have 16 million entries. Eigenvectors and the singular value decomposition (SVD) are tools for looking inside such a matrix and asking: what does it really do, and how much of it actually matters?
The answers turn up all over AI:
- Principal component analysis finds the directions in which a dataset varies most. Those directions are eigenvectors, and in practice they are computed with an SVD.
- Recommender systems approximate a giant users × films table by the product of two thin matrices: a low-rank approximation.
- LoRA, the most popular way to fine-tune large language models cheaply, trains a weight update shaped as the product of two thin matrices, often hundreds of times smaller than the full matrix.
- Whether signals explode or vanish as they pass through many layers of a network, or many steps of an Recurrent Neural Networks, depends on whether the relevant stretch factors are above or below 1. See Vanishing and Exploding Gradients.
- Google's original PageRank scored web pages using the leading eigenvector of a huge matrix of links.
This chapter is the most abstract in the maths part, so we will build it from pictures and examples you can check by hand.
The intuition
Remember from Matrices and Matrix Multiplication that a matrix transforms space: it pulls a rubber sheet of graph paper so that every arrow on it moves. Most arrows get both stretched and turned.
But for many matrices there are a few special directions where arrows are not turned at all. An arrow pointing that way comes out pointing the same way (or exactly backwards), just longer or shorter. These special directions are the matrix's eigenvectors, and the stretch factor for each is its eigenvalue. ("Eigen" is German for "own" or "characteristic": the matrix's own directions.)
Think of stretching a square of dough by pulling its top-right and bottom-left corners apart. The diagonal you pulled along stays a straight diagonal and gets longer. The other diagonal stays put too, perhaps shrinking a little. Every other line in the dough gets tilted. The two diagonals are the eigenvectors of that stretch.
The picture shows the key idea: a circle of arrows becomes an ellipse, and the eigenvectors point along the ellipse's axes. If you know the eigenvectors and eigenvalues, you know what the matrix does: "stretch 3× along this diagonal, leave the other diagonal alone".
Key idea An eigenvector of a matrix is a direction the matrix only stretches, never turns. Its eigenvalue is the stretch factor. The SVD extends the idea to any matrix: every matrix is a rotation, a stretch along the axes, and another rotation.
How it works
The eigenvector equation
In symbols, a non-zero vector is an eigenvector of a square matrix with eigenvalue ("lambda", a scalar) if
Read it as: multiplying by the matrix does the same thing as multiplying by a single number. Check it by hand with
So has eigenvalue 3 and has eigenvalue 1. Compare an ordinary vector, : , which points in a new direction. Not an eigenvector.
Any multiple of an eigenvector is also one ( and are stretched 3× too), so what really matters is the direction. Software returns eigenvectors scaled to length 1.
What the eigenvalue tells you:
| Eigenvalue | Effect along that direction |
|---|---|
| greater than 1 | stretched |
| between 0 and 1 | shrunk |
| exactly 1 | unchanged |
| 0 | squashed flat: information is lost |
| negative | flipped to point backwards, and scaled by |
For a matrix you can find eigenvalues by solving a quadratic equation, but in practice nobody does it by hand. np.linalg.eigh does it in microseconds. Some matrices, such as a quarter-turn rotation, turn every direction and have no real eigenvectors at all.
Applying a matrix again and again
Eigenvalues predict what happens when you apply a matrix many times. Along , applying ten times multiplies by . Along , by . So almost any starting vector ends up pointing nearly along , the eigenvector with the biggest eigenvalue. This is called power iteration, and it is how PageRank was computed.
The same arithmetic explains a problem in deep learning. A signal passing through 50 layers is multiplied by 50 matrices. Stretch factors a little above 1 compound into an explosion. Stretch factors a little below 1 compound into nothing (). This is the root of exploding and vanishing gradients, and why careful Weight Initialization aims to keep the stretch factors close to 1.
Eigendecomposition
When a matrix is symmetric (equal to its own transpose, like our and like every covariance matrix), something especially neat happens. Its eigenvectors are at right angles to each other, and you can rebuild the matrix from them:
Here holds the unit-length eigenvectors as its columns and (capital lambda) is a diagonal matrix with the eigenvalues on the diagonal and zeros elsewhere. This is the eigendecomposition. It says: turn space so the eigenvectors line up with the axes (), stretch each axis by its eigenvalue (), and turn back ().
PCA is exactly this, applied to the covariance matrix of a dataset. The eigenvector with the largest eigenvalue is the direction of greatest spread in the data, the first principal component.
The singular value decomposition
Eigenvectors only exist for square matrices, and the tidy picture above needs symmetry. The singular value decomposition works for every matrix, square or not:
- is a rotation (possibly with a flip) of the input space.
- ("sigma") is diagonal: it stretches along each axis by a non-negative amount. These amounts are the singular values, sorted from largest to smallest.
- is another rotation, into the output space.
So every matrix, however messy, does three simple things in turn: rotate, stretch along the axes, rotate. A unit circle always becomes an ellipse, and the singular values are the lengths of its half-axes.
For the matrix from the Matrices and Matrix Multiplication chapter, the singular values are and . The largest stretch this matrix applies to any arrow of length 1 is 2.29, and the smallest is 0.87.
Rank and low-rank approximation
The number of non-zero singular values is the matrix rank: the number of independent directions the matrix really uses. A matrix of rank 3 squashes everything into a 3-dimensional slice. It looks like a million numbers but carries much less information.
Now the most useful fact in this chapter. The SVD can be written as a sum of simple pieces, one per singular value:
Each piece is a column times a row, scaled by its singular value . Since the are sorted, the first pieces matter most. Keep only the first pieces and you get the low-rank approximation . A theorem (Eckart–Young, 1936) says this is the best possible approximation of rank .
Storing takes about numbers instead of . In the code below, a table secretly built from 3 underlying factors plus noise has three big singular values (100.2, 87.2, 85.2), and then only small ones around 1.8. Keeping rebuilds the table with a relative error of 5.5%, while storing about 540 numbers instead of 8,000.
That is the idea behind several important methods:
- Recommenders. A users × films rating table is approximately low rank, because tastes are driven by a few factors (likes action, likes romance…). Factoring it into two thin matrices fills in the missing ratings.
- LoRA. Hu and colleagues (2021) hypothesised that the change needed to fine-tune a large model has low rank. Instead of updating a weight matrix (16.8 million numbers), LoRA trains () and () and adds to the frozen weights: 65,536 trainable numbers, 256 times fewer.
- Compression. Low-rank factors can shrink layers of a trained network and compress images, at some loss of quality.
In code
import numpy as np
A = np.array([[2.0, 1.0],
[1.0, 2.0]])
vals, vecs = np.linalg.eigh(A) # eigh: for symmetric matrices
print(vals) # [1. 3.] eigenvalues, smallest first
print(vecs) # eigenvectors as COLUMNS, length 1
# [[-0.70710678 0.70710678]
# [ 0.70710678 0.70710678]]
v = vecs[:, 1]
print(A @ v, vals[1] * v) # [2.12132034 2.12132034] [2.12132034 2.12132034] A v = 3 v
# SVD works on any matrix, even non-square ones
M = np.array([[2.0, 1.0],
[0.0, 1.0]])
U, S, Vt = np.linalg.svd(M)
print(S) # [2.28824561 0.87403205] largest first
print(np.allclose(U @ np.diag(S) @ Vt, M)) # True the three pieces rebuild M
# Low-rank approximation of a 100 x 80 matrix that is "really" rank 3 plus noise
rng = np.random.default_rng(0)
X = rng.normal(size=(100, 3)) @ rng.normal(size=(3, 80)) + 0.1 * rng.normal(size=(100, 80))
U, S, Vt = np.linalg.svd(X, full_matrices=False)
print(S[:6].round(1)) # [100.2 87.2 85.2 1.8 1.8 1.8]
for k in [1, 2, 3, 10]:
Xk = U[:, :k] @ np.diag(S[:k]) @ Vt[:k]
err = np.linalg.norm(X - Xk) / np.linalg.norm(X)
print(k, round(err, 3), k * (100 + 80)) # rank, relative error, numbers stored
# 1 0.773 180
# 2 0.542 360
# 3 0.055 540
# 10 0.047 1800
Notice how the error drops sharply at and then barely improves: the extra pieces only describe noise. In PyTorch the same functions are torch.linalg.eigh and torch.linalg.svd, and torch.svd_lowrank computes just the top few pieces of a huge matrix quickly.
Common pitfalls
- Rows versus columns. NumPy returns eigenvectors as the columns of
vecs, not the rows.vecs[0]is a common, wrong guess. - Order.
np.linalg.eighsorts eigenvalues from smallest to largest.np.linalg.svdsorts singular values from largest to smallest.np.linalg.eig(for non-symmetric matrices) does not sort at all, and may return complex numbers. - Signs are arbitrary. If is an eigenvector, so is . Different libraries or versions may flip signs, so don't compare eigenvectors entry by entry.
- Eigenvalues and singular values are different for non-symmetric matrices. Singular values are never negative. For above the eigenvalues are 2 and 1 while the singular values are 2.29 and 0.87.
- Cost. A full SVD of an matrix takes roughly operations. Fine for 1,000 × 1,000. Hopeless for a million × million. Use truncated or randomised methods (
sklearn.decomposition.TruncatedSVD,torch.svd_lowrank) that compute only the top pieces. - Forgetting to centre data for PCA. PCA needs the mean subtracted from each feature first. Without it, the first "component" mostly points at the mean.
Watch out Low rank is an assumption, not a law. If the singular values fall off slowly, a low-rank approximation throws away real information. Always plot the singular values, or measure the error, before choosing .
Where it leads
- PCA and Dimensionality Reduction uses the top eigenvectors of the covariance matrix (via SVD) to compress and visualise data.
- Recommender Systems use low-rank matrix factorisation to predict missing ratings.
- LoRA and Parameter-Efficient Fine-Tuning fine-tunes large models through low-rank updates.
- Vanishing and Exploding Gradients and Weight Initialization are about keeping stretch factors near 1 through deep networks.
- Word Embeddings: some of the earliest word vectors came from an SVD of a word co-occurrence table (latent semantic analysis).
- Quantization and Knowledge Distillation and Small Models are other ways of making big matrices cheaper.
A bit of history
Eigenvalues arose in the 18th and 19th centuries from problems about vibrating strings, rotating bodies and planetary orbits, in the work of Euler, Lagrange and Cauchy. David Hilbert introduced the German prefix "eigen" for these values around 1904. The singular value decomposition was discovered independently by Eugenio Beltrami (1873) and Camille Jordan (1874). Carl Eckart and Gale Young proved in 1936 that truncating the SVD gives the best low-rank approximation. The practical algorithm that computers still use was developed by Gene Golub and William Kahan in 1965, refined by Golub and Christian Reinsch in 1970. In AI, SVD powered latent semantic analysis of text in 1990, the Netflix Prize recommender work of 2006–2009, and in 2021 the LoRA paper by Edward Hu and colleagues at Microsoft brought low rank into the fine-tuning of large language models.
Try it
- By hand, show that and are eigenvectors of . What are the eigenvalues, and what does the matrix do to a circle?
- Start with and apply ten times in NumPy, normalising to length 1 each time. Which direction does approach?
- Load any greyscale image as a matrix (or use
np.random.default_rng(0).random((64, 64))for comparison). Plot its singular values. Rebuild it with and look at the results. Why does the random matrix compress so badly?Hint for 2: you should land on , the eigenvector with the largest eigenvalue. That is power iteration.
Learn more
Hand-picked courses, books, videos and tutorials for going deeper. See all resources →
Essence of Linear Algebra
A visual intuition for vectors, matrices, determinants and eigenvectors. You will see the ideas, not just the rules.
Eigenvectors and Eigenvalues, Explained Visually
Drag vectors around and watch a matrix stretch them. The eigenvectors are the ones that stay on their own line.
MIT 18.06: Linear Algebra
The classic university linear algebra course, with full video lectures, notes and problem sets. Strang explains matrices as things that act on vectors.
Mathematics for Machine Learning
The linear algebra, calculus, probability and optimisation that ML uses, in one free book.
Immersive Linear Algebra
A free linear algebra book whose figures you can drag and rotate. Excellent for seeing vectors, dot products and matrices as geometry.
LoRA: Low-Rank Adaptation of Large Language Models
Fine-tuning by learning small low-rank updates instead of all weights.
Facts checked as of 30 November 2026. Fast-moving details (products, prices, laws) change often. · Source: content/entries/math/eigenvectors-and-svd.md