Eigenvalues and Eigenvectors
The rare directions a matrix leaves pointing the same way, merely stretched — and the stretch factors that tell you what the matrix really does.
Why Does This Exist?
"Just lower the learning rate" is advice you have probably given and received. Eigenvalues explain why it works, why it is unsatisfying, and what the actual problem is.
The curvature of your loss surface in each direction is an eigenvalue of the Hessian. When the largest is 1000x the smallest, any single learning rate is simultaneously too large for the steep directions — where it overshoots and oscillates — and far too small for the shallow ones, where progress crawls. That ratio is the condition number, and it is the real reason training is slow. Adaptive per-parameter step sizes are an approximation to fixing it.
The same numbers show up in three more places you use. PCA finds the eigenvectors of the covariance matrix, and their eigenvalues are exactly how much variance each direction carries. The spectral norm of a weight matrix is its largest singular value, which for symmetric matrices is an eigenvalue. And PageRank is one long eigenvector computation.
Think of It Like This
Stretching a sheet of rubber
Pin a sheet of rubber to a table and pull it — harder east-west than north-south. Draw arrows on it beforehand and watch what happens.
Most arrows both grow and swing round, because they get pulled more in one direction than the other and end up pointing somewhere new. But two special families do not rotate at all. An arrow lying exactly along the east-west pull just gets longer. One lying exactly north-south also just gets longer, by a different amount. Those are the eigenvectors, and the two stretch factors are the eigenvalues.
Knowing them tells you everything about the stretch, because any arrow can be split into an east-west part and a north-south part, each of which you know how to stretch. A complicated deformation collapses into two independent scalings.
Two extreme cases are worth holding on to. A stretch factor of means that direction is untouched. A factor of means the sheet was crushed flat along that direction, and no pulling recovers what was there. The analogy stops at linearity: rubber resists non-uniformly at large stretches, while a matrix stretches every length by the same factor.
How It Actually Works
An eigenvector of a square matrix is a nonzero vector whose direction survives the transformation:
In plain words: applying the matrix to gives back scaled by a number. That number is the eigenvalue. The whole set of eigenvalues is the matrix spectrum, which is where "spectral" in spectral norm and spectral clustering comes from.
Eigenvectors come in families: if works, so does any multiple of it, so implementations return unit-length representatives and the sign is arbitrary.
Finding them
Rearrange to . For a nonzero to satisfy this, the matrix must destroy a direction — it must be singular. So:
In plain words: the eigenvalues are exactly the values that make collapse. Expanding that determinant gives the characteristic polynomial, of degree , so an matrix has eigenvalues counted with multiplicity.
Nobody computes it this way past — root-finding on a degree-1000 polynomial is numerically hopeless. Real implementations use iterative algorithms, and the simplest is worth knowing: power iteration repeatedly multiplies a random vector by and renormalises. It converges to the dominant eigenvector, because that component grows fastest. PageRank is power iteration, and so is the spectral-norm estimate in spectral normalisation.
Two free checks
These catch a large fraction of implementation errors, and both are one line:
In plain words: the eigenvalues sum to the diagonal total and multiply to the determinant. Always use them when you compute eigenvalues by hand.
Symmetric matrices are the good case
For a symmetric matrix () three things all become true at once: every eigenvalue is real, eigenvectors of distinct eigenvalues are orthogonal, and the matrix decomposes as
with orthogonal and diagonal. This is the spectral theorem, and it is why symmetric matrices are so much nicer to work with. The symmetric upgrade is worked fully in eigendecomposition of symmetric matrices.
It matters because the matrices you actually care about are symmetric. Covariance matrices are, which is what makes PCA well behaved. Hessians are, which is what makes curvature analysis meaningful. Graph Laplacians and Gram matrices are.
Non-symmetric matrices can have complex eigenvalues — a rotation matrix has no real eigenvector, because no direction survives a rotation. This is the source of a common code surprise, covered below.
What the eigenvalues tell you
- Sign — for a symmetric matrix, all positive means positive definite, so a bowl and a minimum. All negative, a maximum. Mixed signs, a saddle. This is how the Hessian classifies a stationary point.
- Magnitude — the largest, , is the spectral radius, and it governs stability: repeated multiplication grows if it exceeds and decays if below. This is the vanishing and exploding gradient story in recurrent networks, stated precisely.
- Ratio — the condition number measures how badly stretched the geometry is. Large means ill-conditioned: slow optimisation and sensitivity to small input changes.
Worked example
Take , which is symmetric, so expect real eigenvalues and orthogonal eigenvectors.
Hand-computed characteristic polynomial:
Factoring gives , so and .
Check both free identities: trace is and . Determinant is and .
For , solve , which is , giving , so . Verify directly: .
For : gives , so . Verify: .
The two eigenvectors are orthogonal: .
Condition number: . Mild. And a non-eigenvector confirms the contrast — , which points in a new direction, exactly as the diagram shows.
Code
Eigenvalues and , trace , determinant , orthogonal eigenvectors — every number matches the hand calculation.
import numpy as np
A = np.array([[2.0, 1.0], [1.0, 2.0]]) # symmetric
vals, vecs = np.linalg.eigh(A) # eigh: symmetric, real, ascendingprint(vals) # -> [1. 3.]print(round(vals.sum(), 10), round(np.trace(A), 10)) # -> 4.0 4.0print(round(float(np.prod(vals)), 10), round(np.linalg.det(A), 10)) # -> 3.0 3.0
v = vecs[:, 1] # eigenvector for lambda = 3print(np.allclose(A @ v, 3 * v)) # -> Trueprint(round(float(vecs[:, 0] @ vecs[:, 1]), 10)) # -> 0.0 orthogonal
# A rotation has NO real eigenvector, so eig() returns complex values.R = np.array([[0.0, -1.0], [1.0, 0.0]])print(np.linalg.eigvals(R)) # -> [0.+1.j 0.-1.j]print(round(vals[1] / vals[0], 4)) # -> 3.0 condition numberThe rotation matrix is the complex case: no real direction survives a 90-degree turn.
Watch Out For
Using eig where eigh belongs
np.linalg.eig handles general matrices and therefore returns complex arrays, in arbitrary order. np.linalg.eigh is for symmetric matrices and returns real values, sorted ascending, using a faster and more accurate algorithm.
Call eig on a covariance matrix and you get eigenvalues like 2.9999999+0.j. They are correct and complex dtype — so downstream comparisons behave oddly and plotting libraries warn. People then chase a phantom bug in their PCA.
There is a subtler version. A matrix that should be symmetric often is not exactly, because floating-point arithmetic leaves asymmetries around . The fix is to symmetrise explicitly — A = (A + A.T) / 2 — and then call eigh.
Rule of thumb: if the matrix is a covariance, Gram matrix, Hessian, or graph Laplacian, use eigh.
Reading eigenvalues from a matrix that was never scaled
Eigenvalues carry the units of your data, so they are meaningless across features measured on different scales.
The classic case is PCA on unscaled data. Include a feature in metres and another in millimetres and the millimetre feature has a variance a million times larger, so the first principal component points almost entirely along it. You conclude that feature is important, when all you measured was your choice of unit.
So standardise features before any eigen-based analysis, and when you report a spectrum, report the proportions — each eigenvalue over their sum — rather than raw values. Proportions are unit-free and comparable.
The Quick Version
- : an eigenvector keeps its direction, the eigenvalue is the stretch factor. The set of them is the spectrum.
- Here gives on and on , with trace and determinant as free checks.
- They solve , but nobody computes it that way past . Power iteration finds the dominant one.
- Two free checks: eigenvalues sum to the trace and multiply to the determinant.
- Symmetric matrices give real eigenvalues, orthogonal eigenvectors, and .
- Non-symmetric matrices can have complex eigenvalues — a rotation has no real eigenvector.
- Signs classify a stationary point: all positive is a minimum, mixed is a saddle.
- The condition number is why one global learning rate struggles.
- Use
eighfor symmetric matrices, and symmetrise first if floating point made it slightly asymmetric.