np.linalg.eig()
Eigenvalues and eigenvectors reveal the directions a matrix only stretches, and by how much.
In this page:
Syntax
eigenvalues, eigenvectors = np.linalg.eig(matrix)
np.linalg.eig()
np.linalg.eig returns a pair: an array of eigenvalues and a matrix whose columns are the matching eigenvectors. They satisfy A v = lambda v. Eigen-decomposition underpins PCA and many physics and data-science methods.
Note:
For symmetric matrices use np.linalg.eigh; it is faster and returns real values.
Example: np.linalg.eig()
import numpy as np
A = np.array([[2, 0], [0, 3]])
vals, vecs = np.linalg.eig(A)
print(sorted(vals))
v = vecs[:, 0]
print(np.allclose(A @ v, vals[0] * v))
# Output:
# [2.0, 3.0]
# True
Related Topics
Common Mistakes
- Reading eigenvectors from rows instead of columns
- Assuming eigenvalues come sorted
- Ignoring complex results for non-symmetric matrices
Chapter Summary
- eig returns eigenvalues and eigenvectors
- Eigenvectors are columns
- Order is not guaranteed
- eigh suits symmetric matrices
🔒
Chapter Quiz — Complete all 6 topics to unlock
0/6 topics done
Complete these topics first: