Python eigenvectors

点点圈 提交于 2019-12-09 16:45:21

问题


eigenvalues, eigenvectors = linalg.eig(K)

How can I print just eigenvectors of len(K). So if there is K, 2x2 matrix, I get 4 eigenvectors, how can I print just 2 of them if there is len(K)=2....

Many thanks


回答1:


You are getting two vectors of length two, not four vectors. For example:

In [1]: import numpy as np

In [2]: K=np.random.normal(size=(2,2))

In [3]: eigenvalues, eigenvectors = np.linalg.eig(K)

In [4]: eigenvectors
Out[4]: 
array([[ 0.83022467+0.j        ,  0.83022467+0.j        ],
       [ 0.09133956+0.54989461j,  0.09133956-0.54989461j]])

In [5]: eigenvectors.shape
Out[5]: (2, 2)

The first vector is eigenvectors[:,0], the second is eigenvectors[:,1].




回答2:


From the manual:

The normalized eigenvector corresponding to the eigenvalue w[i] is the column v[:,i].



来源:https://stackoverflow.com/questions/5953297/python-eigenvectors

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!