Chr*_*ano 4 numpy eigenvector python-2.7
如何计算python中的左侧特征向量?
>>> import from numpy as np
>>> from scipy.linalg import eig
>>> np.set_printoptions(precision=4)
>>> T = np.mat("0.2 0.4 0.4;0.8 0.2 0.0;0.8 0.0 0.2")
>>> print "T\n", T
T
[[ 0.2 0.4 0.4]
[ 0.8 0.2 0. ]
[ 0.8 0. 0.2]]
>>> w, vl, vr = eig(T, left=True)
>>> vl
array([[ 0.8165, 0.8165, 0. ],
[ 0.4082, -0.4082, -0.7071],
[ 0.4082, -0.4082, 0.7071]])
Run Code Online (Sandbox Code Playgroud)
这似乎不正确,谷歌对此并不友好!
Your result is correct to my understanding.
However, you might be misinterpreting it. The numpy docs are a bit clearer on what the left eigenvectors should be.
Finally, it is emphasized that v consists of the right (as in right-hand side) eigenvectors of a. A vector y satisfying dot(y.T, a) = z * y.T for some number z is called a left eigenvector of a, and, in general, the left and right eigenvectors of a matrix are not necessarily the (perhaps conjugate) transposes of each other.
即您需要转置vl. vl[:,i].T是第 i 个左特征向量。如果我对此进行测试,我会得到结果是正确的。
>>> import numpy as np
>>> from scipy.linalg import eig
>>> np.set_printoptions(precision=4)
>>> T = np.mat("0.2 0.4 0.4;0.8 0.2 0.0;0.8 0.0 0.2")
>>> print "T\n", T
T
[[ 0.2 0.4 0.4]
[ 0.8 0.2 0. ]
[ 0.8 0. 0.2]]
>>> w, vl, vr = eig(T, left=True)
>>> vl
array([[ 0.8165, 0.8165, 0. ],
[ 0.4082, -0.4082, -0.7071],
[ 0.4082, -0.4082, 0.7071]])
>>> [ np.allclose(np.dot(vl[:,i].T, T), w[i]*vl[:,i].T) for i in range(3) ]
[True, True, True]
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5700 次 |
| 最近记录: |