bundles / numpy 2.5.0.dev0+git20251130.2de293a / numpy / linalg / eig
_ArrayFunctionDispatcher
numpy.linalg:eig
source: build-install/usr/lib/python3.14/site-packages/numpy/linalg/_linalg.py :1362
Signature
def eig ( a ) Summary
Compute the eigenvalues and right eigenvectors of a square array.
Parameters
a: (..., M, M) arrayMatrices for which the eigenvalues and right eigenvectors will be computed
Returns
: A namedtuple with the following attributes:eigenvalues: (..., M) arrayThe eigenvalues, each repeated according to its multiplicity. The eigenvalues are not necessarily ordered. The resulting array will be of complex type, unless the imaginary part is zero in which case it will be cast to a real type. When
ais real the resulting eigenvalues will be real (0 imaginary part) or occur in conjugate pairseigenvectors: (..., M, M) arrayThe normalized (unit "length") eigenvectors, such that the column
eigenvectors[:,i]is the eigenvector corresponding to the eigenvalueeigenvalues[i].
Raises
: LinAlgErrorIf the eigenvalue computation does not converge.
Notes
Broadcasting rules apply, see the numpy.linalg documentation for details.
This is implemented using the _geev LAPACK routines which compute the eigenvalues and eigenvectors of general square arrays.
The number w is an eigenvalue of a if there exists a vector v such that a @ v = w * v. Thus, the arrays a, eigenvalues, and eigenvectors satisfy the equations a @ eigenvectors[:,i] = eigenvalues[i] * eigenvectors[:,i] for .
The array eigenvectors may not be of maximum rank, that is, some of the columns may be linearly dependent, although round-off error may obscure that fact. If the eigenvalues are all different, then theoretically the eigenvectors are linearly independent and a can be diagonalized by a similarity transformation using eigenvectors, i.e, inv(eigenvectors) @ a @ eigenvectors is diagonal.
For non-Hermitian normal matrices the SciPy function scipy.linalg.schur is preferred because the matrix eigenvectors is guaranteed to be unitary, which is not the case when using eig. The Schur factorization produces an upper triangular matrix rather than a diagonal matrix, but for normal matrices only the diagonal of the upper triangular matrix is needed, the rest is roundoff error.
Finally, it is emphasized that eigenvectors consists of the right (as in right-hand side) eigenvectors of a. A vector y satisfying y.T @ a = z * y.T for some number z is called a left eigenvector of a, and, in general, the left and right eigenvectors of a matrix are not necessarily the (perhaps conjugate) transposes of each other.
Examples
import numpy as np from numpy import linalg as LA✓
eigenvalues, eigenvectors = LA.eig(np.diag((1, 2, 3))) eigenvalues eigenvectors✓
eigenvalues, eigenvectors = LA.eig(np.array([[1, -1], [1, 1]])) eigenvalues eigenvectors✓
a = np.array([[1, 1j], [-1j, 1]]) eigenvalues, eigenvectors = LA.eig(a) eigenvalues✓
eigenvectors
✗a = np.array([[1 + 1e-9, 0], [0, 1 - 1e-9]]) eigenvalues, eigenvectors = LA.eig(a) eigenvalues eigenvectors✓
See also
- eigh
eigenvalues and eigenvectors of a real symmetric or complex Hermitian (conjugate symmetric) array.
- eigvals
eigenvalues of a non-symmetric array.
- eigvalsh
eigenvalues of a real symmetric or complex Hermitian (conjugate symmetric) array.
- scipy.linalg.eig
Similar function in SciPy that also solves the generalized eigenvalue problem.
- scipy.linalg.schur
Best choice for unitary and other non-Hermitian normal matrices.
Aliases
-
numpy.linalg.eig