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 1000× 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. Adam's 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 — its largest singular value, which for symmetric matrices is an eigenvalue — is what spectral normalisation constrains in GANs. 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 1 means that direction is untouched. A factor of 0 means the sheet was crushed flat along that direction, and no amount of pulling recovers what was there.
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's 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 relative to the others. PageRank is power iteration, and so is the spectral-norm estimate in spectral normalisation, usually with a single iteration per training step.
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.
It matters because the matrices you actually care about are symmetric. Covariance matrices are, which is what makes PCA well behaved and its components orthogonal. 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 exactly how the Hessian classifies a stationary point.
- Magnitude — the largest, , is the spectral radius, and it governs stability: repeated multiplication grows if it exceeds 1 and decays if it is 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.
The 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, as the spectral theorem promised: ✓.
Condition number: . Mild. And a non-eigenvector confirms the contrast — , which points in a new direction, exactly as the diagram shows.
Show Me the Code
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 numberEigenvalues 1 and 3, trace 4, determinant 3, orthogonal eigenvectors — every number matches the hand calculation. The rotation matrix is the complex case from the next section.
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 or Hermitian 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 they are complex dtype — so downstream comparisons behave oddly, np.sort on complex values sorts by real part then imaginary, plotting libraries warn or silently discard the imaginary part, and any if lambda > 0 test raises or misbehaves. 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 in X.T @ X leaves asymmetries around . eig will then hand back genuinely complex eigenvalues with tiny imaginary parts. The fix is to symmetrise explicitly — A = (A + A.T) / 2 — and then call eigh.
Rule of thumb: if the matrix is a covariance, a Gram matrix, a Hessian, or a graph Laplacian, use eigh. Reach for eig only when the matrix genuinely is not symmetric, and then expect complex results as normal rather than as an error.
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 — and the conclusions you draw from them are then wrong rather than merely imprecise.
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 it dominates the covariance matrix, and the first principal component points almost entirely along it. You conclude that feature is the important one, when all you measured was your choice of unit.
Condition numbers suffer identically. An ill-conditioned matrix caused purely by feature scaling looks like a hard optimisation problem, and rescaling fixes it entirely — which is a large part of why feature standardisation speeds up training so reliably. It is not a trick; it is removing artificial anisotropy from the loss surface.
So standardise features before any eigen-based analysis, and when you report an eigenvalue spectrum, report the proportions — each eigenvalue over their sum — rather than the raw values. Proportions are unit-free and comparable; raw eigenvalues are neither.
The Quick Version
- : an eigenvector keeps its direction, the eigenvalue is the stretch factor. The set of them is the spectrum.
- They solve , but nobody computes it that way past . Iterative methods, and power iteration for the dominant one.
- Two free checks: eigenvalues sum to the trace and multiply to the determinant.
- Symmetric matrices give real eigenvalues, orthogonal eigenvectors, and . Covariance, Hessians, Laplacians and Gram matrices are all symmetric.
- 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 spectral radius governs stability under repeated multiplication — the exploding/vanishing gradient story.
- The condition number is why one global learning rate struggles, and what adaptive optimisers approximate away.
- Use
eighfor symmetric matrices, and symmetrise first if floating point made it slightly asymmetric. - Standardise features first, and report eigenvalue proportions rather than raw values.
What to Read Next
- Singular Value Decomposition generalises this to non-square matrices and is what you actually use in practice.
- Linear Transformations is the geometry an eigenvector is a fixed direction of.
- Vector Spaces and Rank explains why a zero eigenvalue means information was destroyed.
- Norms — the spectral norm is the largest singular value, and for symmetric matrices the largest absolute eigenvalue.
- Graph Laplacian and Spectral Views is the second major payoff, on a matrix built from a graph rather than from data.
- Definitions worth a look: Hessian Matrix, Matrix Rank, Covariance, and Convex Function.
- Related interview question: What is the difference between variance and covariance?