Matrix spectral analysis
Analyze linear transformations or matrix dynamics by examining characteristic values and directions.
NumPy · Function
Computes the eigenvalues and right eigenvectors of a square array. It returns paired eigenvalues and normalized eigenvectors, including support for batched square matrices.
Pass a square array to obtain a namedtuple containing eigenvalues and corresponding right eigenvectors. Each eigenvector is returned as a normalized column, so column i pairs with eigenvalue i; stacked leading dimensions are supported.
numpy.linalg.eig(a)| Name | Type | Description |
|---|---|---|
a | array | Matrix or batch of matrices with shape (..., M, M) for which eigenvalues and right eigenvectors are computed. |
A namedtuple with eigenvalues of shape (..., M) and eigenvectors of shape (..., M, M). Eigenvalues are not necessarily ordered; eigenvectors are normalized and column i corresponds to eigenvalues[i].
import numpy as np
A = np.array([[1, 2], [2, 1]])
w, v = np.linalg.eig(A)
print(w)
print(v)
print(np.allclose(A @ v, v * w))Computes eigenvalues and verifies each returned eigenvector equation.
Analyze linear transformations or matrix dynamics by examining characteristic values and directions.
Process multiple square matrices at once while retaining leading batch dimensions.
Verify numerical solutions by checking the eigenvector equation for returned pairs.
It computes the eigenvalues and right eigenvectors of a square array. The result is a namedtuple with eigenvalues and eigenvectors fields.
Follow-up: How do you match an eigenvalue to its vector? Use the same index: eigenvectors[:, i] corresponds to eigenvalues[i].
The input has shape (..., M, M), allowing optional leading batch dimensions. The final two dimensions must form square matrices.
Follow-up: What shape does a batched result have? Eigenvalues retain the leading dimensions and have shape (..., M); eigenvectors have shape (..., M, M).
Each returned eigenvector is normalized to unit length, and the vectors are stored as columns. The eigenvalue and vector at each index form a corresponding eigenpair.
Follow-up: How can an eigenpair be checked numerically? Verify A @ v[:, i] is close to eigenvalues[i] * v[:, i].
numpy.linalg.eigvalsnumpy.linalg.eighnumpy.linalg.eigvalshnumpy.linalg.svd