Python eigenvectors

thaking picture thaking · May 10, 2011 · Viewed 21.8k times · Source
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

Answer

NPE picture NPE · May 10, 2011

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].