Eigenvectors and eigenvalues
Quick answer
An eigenvector is a nonzero vector whose direction lies on the same line after a square matrix transforms it: A v = λ v. The eigenvalue λ tells how the vector is scaled. A negative value reverses its direction; zero sends it to zero. In ML, eigenvectors of a covariance matrix reveal directions of variation. We use real symmetric matrices here, which have real eigenvalues and an orthonormal eigenbasis. General square matrices may have complex eigenvalues or lack a full eigenbasis.
Check an eigenpair by hand
For A = [[3, 1], [1, 3]], multiplying by [1, 1] yields [4, 4]. Thus λ = 4. Multiplying by [1, -1] yields [2, -2], so λ = 2. A vector such as [1, 0] does not stay on its original line. The code computes each side independently.
A = [[3, 1], [1, 3]]v = [1, -1]lam = 2print([sum(a*b for a, b in zip(row, v)) for row in A])print([lam*x for x in v])Expected output:
[2, -2][2, -2]Both sides match, and v is nonzero. Scaling v by any nonzero scalar gives another eigenvector for the same eigenvalue.
Check a symmetric eigendecomposition
Optional local lab (Python 3.13.5, NumPy 2.3.5, CPU, float64). Use np.linalg.eigh for the real symmetric matrix. It returns eigenvalues in ascending order and eigenvectors in columns. Multiplying Q * w scales the columns of Q; @ multiplies matrices. Compare numerical identities with absolute and relative tolerances. Q.T @ Q should equal the identity matrix.
import numpy as npA = np.array([[3., 1.], [1., 3.]])w, Q = np.linalg.eigh(A)print(w.round(8).tolist())print(bool(np.allclose(A @ Q, Q * w, atol=1e-12, rtol=1e-12)))print(bool(np.allclose(Q.T @ Q, np.eye(2), atol=1e-12, rtol=1e-12)))Expected output:
[2.0, 4.0]TrueTrueThe two perpendicular directions are scaled by 2 and 4. The signs of eigenvectors can differ between valid implementations; a repeated eigenvalue can even admit different orthonormal bases for its eigenspace.
Common mistakes
Never accept the zero vector as an eigenvector, even though both sides of the equation are zero. Do not apply eigh to an arbitrary nonsymmetric matrix: this routine assumes symmetry (Hermitian structure in the complex case) and does not generally verify it. Compare residuals and subspaces, not exact signed eigenvectors.
Practice and next steps
For diag(5, -2), identify eigenvectors along the coordinate axes and describe what happens to each. Next, use a symmetric covariance matrix to find directions of spread.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Eigenvectors and eigenvalues — knowledge check
Apply matrix geometry to small numerical fixtures.
Which vector is disallowed as an eigenvector?
A v = -3 v for nonzero v. What happens?
For diag(2,5), which eigenvalue belongs to [0,1]?
Which matrix is appropriate for eigh in this real-valued lesson?
Two valid solvers return opposite signs for a unit eigenvector. What should you check?