eig
- scipy.linalg.eig(a, b=None, left=False, right=True, overwrite_a=False, overwrite_b=False, check_finite=True, homogeneous_eigvals
Solve an ordinary or generalized eigenvalue problem of a square matrix.
Find eigenvalues w and right or left eigenvectors of a general matrix:
a @ vr[:, i] = w[i] * b @ vr[:, i]
a.H @ vl[:, i] = w[i].conj() * b.H @ vl[:, i]
where .H is the Hermitian conjugation.
A complex or real matrix whose eigenvalues and eigenvectors will be computed.
Right-hand side matrix in a generalized eigenvalue problem. Default is None, identity matrix is assumed.
Whether to calculate and return left eigenvectors. Default is False.
Whether to calculate and return right eigenvectors. Default is True.
Whether to overwrite a; may improve performance. Default is False. See overwrite_* arguments for details.
Array arguments of this function, a and b, may have additional “batch” dimensions prepended to the core shape. In this case, the array is treated as a batch of lower-dimensional slices; see Batched Linear Operations for details.
>>> import numpy as np
>>> from scipy import linalg
>>> a = np.array([[0., -1.],
... [1., 0.]])
Whether to overwrite b; may improve performance. Default is False. See overwrite_* arguments for details.
Whether to check that the input matrices contain only finite numbers. Disabling may give a performance gain, but may result in problems (crashes, non-termination) if the inputs do contain infinities or NaNs.
If True, return the eigenvalues in homogeneous coordinates.
In this case w is a (2, M) array so that:
w[1, i] * a @ vr[:, i] = w[0, i] * b @ vr[:, i]
This option is sometimes useful for generalized eigenvalue problems,
b is not None, where an eigenvalue, ,
can over- or underflow; typically, :math:alpha and are of the
order of norm(a) and norm(b), respectively.
Default is False.
The eigenvalues, each repeated according to its
multiplicity. The shape is (..., M) unless homogeneous_eigvals=True.
The left eigenvector corresponding to the eigenvalue
w[i] is the column vl[:, i]. Only returned if left=True.
The left eigenvector is not normalized.
The normalized right eigenvector corresponding to the eigenvalue
w[i] is the column vr[:, i]. Only returned if right=True (default).
If eigenvalue computation does not converge.
eigenvalues and right eigenvectors for symmetric/Hermitian tridiagonal matrices
Compute the eigenvalues (eigvals is the same as eig(a, right=False))
>>> linalg.eigvals(a)
array([0.+1.j, 0.-1.j])
Solve a generalized eigenvalue problem:
>>> b = np.array([[0., 1.], [1., 1.]])
>>> linalg.eigvals(a, b)
array([ 1.+0.j, -1.+0.j])
Inputs with ndim > 2 are interpreted as a batch of matrices
>>> a2 = np.stack((a, 2*a))
>>> linalg.eigvals(a2)
array([[0.+1.j, 0.-1.j],
[0.+2.j, 0.-2.j]])
homogeneous_eigvals=True argument effectively separates each eigenvalue into a
numerator-denominator pair:
>>> a = np.array([[3., 0., 0.],
... [0., 8., 0.],
... [0., 0., 7.]])
>>> b = 2*np.eye(3)
>>> linalg.eigvals(a, b, homogeneous_eigvals=True)
array([[3.+0.j, 8.+0.j, 7.+0.j],
[2.+0.j, 2.+0.j, 2.+0.j]])
Eigenvectors: by default, eig returns normalized right eigenvectors in
columns of the second return array
>>> a = np.array([[0., -1.],
... [1., 0.]])
>>> w, vr = linalg.eig(a)
>>> w # eigenvalues
array([0. + 1.j, 0. - 1.j])
>>> vr # normalized right eigenvectors
array([[0.70710678 + 0.j , 0.70710678 - 0.j ],
[0. - 0.70710678j, 0. + 0.70710678j]])
Verify that columns of vr are indeed eigenvectors:
>>> a @ vr[:, 0] - w[0] * vr[:, 0]
array([0.+0.j, 0.+0.j])
>>> a @ vr[:, 1] - w[1] * vr[:, 1]
array([0.+0.j, 0.+0.j])
To compute the normalized left eigenvectors, use left=True:
>>> w, vl, vr = linalg.eig(a, left=True, right=True)
>>> vl * np.sqrt(2) # ``vl`` is normalized left eigenvectors
array([[-1. + 0.j, -1. - 0.j],
[ 0. + 1.j, 0. - 1.j]])
>>> vr * np.sqrt(2) # ``vr`` is normalized right eigenvectors
array([[1. + 0.j, 1. + 0.j],
[0. - 1.j, 0. + 1.j]])