numpy.linalg.eig#

linalg.eig(a)[source]#

Compute the eigenvalues and right eigenvectors of a square array.

Parameters:
a(…, M, M) array

Matrices for which the eigenvalues and right eigenvectors willbe computed

Returns:
A namedtuple with the following attributes:
eigenvalues(…, M) array

The eigenvalues, each repeated according to its multiplicity.The eigenvalues are not necessarily ordered. The resultingarray will be of complex type, unless the imaginary part iszero in which case it will be cast to a real type. Whenais real the resulting eigenvalues will be real (0 imaginarypart) or occur in conjugate pairs

eigenvectors(…, M, M) array

The normalized (unit “length”) eigenvectors, such that thecolumneigenvectors[:,i] is the eigenvector corresponding to theeigenvalueeigenvalues[i].

Raises:
LinAlgError

If the eigenvalue computation does not converge.

See also

eigvals

eigenvalues of a non-symmetric array.

eigh

eigenvalues and eigenvectors of a real symmetric or complex Hermitian (conjugate 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.

Notes

Broadcasting rules apply, see thenumpy.linalg documentation fordetails.

This is implemented using the_geev LAPACK routines which computethe eigenvalues and eigenvectors of general square arrays.

The numberw is an eigenvalue ofa if there exists a vectorv suchthata@v=w*v. Thus, the arraysa,eigenvalues, andeigenvectors satisfy the equationsa@eigenvectors[:,i]=eigenvalues[i]*eigenvectors[:,i] for\(i \in \{0,...,M-1\}\).

The arrayeigenvectors may not be of maximum rank, that is, some of thecolumns may be linearly dependent, although round-off error may obscurethat fact. If the eigenvalues are all different, then theoretically theeigenvectors are linearly independent anda can be diagonalized by asimilarity transformation usingeigenvectors, i.e,inv(eigenvectors)@a@eigenvectors is diagonal.

For non-Hermitian normal matrices the SciPy functionscipy.linalg.schuris preferred because the matrixeigenvectors is guaranteed to beunitary, which is not the case when usingeig. The Schur factorizationproduces an upper triangular matrix rather than a diagonal matrix, but fornormal matrices only the diagonal of the upper triangular matrix isneeded, the rest is roundoff error.

Finally, it is emphasized thateigenvectors consists of theright (asin right-hand side) eigenvectors ofa. A vectory satisfyingy.T@a=z*y.T for some numberz is called aleft eigenvector ofa,and, in general, the left and right eigenvectors of a matrix are notnecessarily the (perhaps conjugate) transposes of each other.

References

G. Strang,Linear Algebra and Its Applications, 2nd Ed., Orlando, FL,Academic Press, Inc., 1980, Various pp.

Examples

>>>importnumpyasnp>>>fromnumpyimportlinalgasLA

(Almost) trivial example with real eigenvalues and eigenvectors.

>>>eigenvalues,eigenvectors=LA.eig(np.diag((1,2,3)))>>>eigenvaluesarray([1., 2., 3.])>>>eigenvectorsarray([[1., 0., 0.],       [0., 1., 0.],       [0., 0., 1.]])

Real matrix possessing complex eigenvalues and eigenvectors;note that the eigenvalues are complex conjugates of each other.

>>>eigenvalues,eigenvectors=LA.eig(np.array([[1,-1],[1,1]]))>>>eigenvaluesarray([1.+1.j, 1.-1.j])>>>eigenvectorsarray([[0.70710678+0.j        , 0.70710678-0.j        ],       [0.        -0.70710678j, 0.        +0.70710678j]])

Complex-valued matrix with real eigenvalues (but complex-valuedeigenvectors); note thata.conj().T==a, i.e.,a is Hermitian.

>>>a=np.array([[1,1j],[-1j,1]])>>>eigenvalues,eigenvectors=LA.eig(a)>>>eigenvaluesarray([2.+0.j, 0.+0.j])>>>eigenvectorsarray([[ 0.        +0.70710678j,  0.70710678+0.j        ], # may vary       [ 0.70710678+0.j        , -0.        +0.70710678j]])

Be careful about round-off error!

>>>a=np.array([[1+1e-9,0],[0,1-1e-9]])>>># Theor. eigenvalues are 1 +/- 1e-9>>>eigenvalues,eigenvectors=LA.eig(a)>>>eigenvaluesarray([1., 1.])>>>eigenvectorsarray([[1., 0.],       [0., 1.]])
On this page