简体   繁体   中英

In which order eigen values repeated in np.linalg.eig?

Documentation says that eigenvalues are repeated according to its multiplicity and the are not ordered. When I print w it gives me [5,3,5,1]. Why eigenvalues appear in this order. What is the storing order for eigen vectors? Is it same as for eigenvalues?

B = np.array([[5,-2,6,-1],[0,3,-8,0],[0,0,5,4],[0,0,0,1]])
print(B)
print(B.shape)
w, v= np.linalg.eig(B)
print("eigenvalues are: ", w)

Yes the eigenvectors will be in the same order, you can verify this by adding just two lines to your code

import numpy as np
B=np.array([[5,-2,6,-1],[0,3,-8,0],[0,0,5,4],[0,0,0,1]])
print(B)
print(B.shape)
w,v= np.linalg.eig(B)
print("eigenvalues are: ", w)

for i in range(4):
    print (np.dot((B-w[i]*np.eye(4)),v[:,i]))

As far as the concept of multiplicity is concerned, a single eigenvalue can be associated with multiple linearly independent eigenvectors. You can read more about this here

The documentation provides the following information regarding the eigenvectors.

The normalized (unit “length”) eigenvectors, such that the column v[:,i] is the eigenvector corresponding to the eigenvalue w[i].

In other words, the order of eigenvalues is arbitrary in principle. But whatever order of the eigenvalues, the order will match the eigenvectors.

You can verify that the eigenvalues and eigenvector orders match by computing the application of B to the column vectors of v . In code,

for i in range(B.shape[0]):
    # Apply B to the eigenvectors
    scaled = np.dot(B, v[:, i])
    # Check that applying B only applies a scaling to the eigenvector
    np.testing.assert_allclose(scaled, w[i] * v[:, i])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM