我试图找到以下矩阵的特征值/向量:
A = np.array([[1, 0, 0],
[0, 1, 0],
[1, 1, 0]])
使用代码:
from numpy import linalg as LA
e_vals, e_vecs = LA.eig(A)
我得到了这个答案:
print(e_vals)
[ 0. 1. 1.]
print(e_vecs)
[[ 0. 0.70710678 0. ]
[ 0. 0. 0.70710678]
[ 1. 0.70710678 0.70710678]]
但是,我认为以下应该是答案。
[1] Real Eigenvalue = 0.00000
[1] Real Eigenvector:
0.00000
0.00000
1.00000
[2] Real Eigenvalue = 1.00000
[2] Real Eigenvector:
1.00000
0.00000
1.00000
[3] Real Eigenvalue = 1.00000
[3] Real Eigenvector:
0.00000
1.00000
1.00000
也就是说,特征值 - 特征向量问题表明以下情况应该成立:
# A * e_vecs = e_vals * e_vecs
print(A.dot(e_vecs))
[[ 0. 0.70710678 0. ]
[ 0. 0. 0.70710678]
[ 0. 0.70710678 0.70710678]]
print(e_vals.dot(e_vecs))
[ 1. 0.70710678 1.41421356]
答案 0 :(得分:4)
linalg.eig
返回的特征值是列向量,因此您需要迭代e_vecs
的转置(因为默认情况下,2D数组上的迭代会返回行向量) :
import numpy as np
import numpy.linalg as LA
A = np.array([[1, 0, 0], [0, 1, 0], [1, 1, 0]])
e_vals, e_vecs = LA.eig(A)
print(e_vals)
# [ 0. 1. 1.]
print(e_vecs)
# [[ 0. 0. 1. ]
# [ 0.70710678 0. 0.70710678]
# [ 0. 0.70710678 0.70710678]]
for val, vec in zip(e_vals, e_vecs.T):
assert np.allclose(np.dot(A, vec), val * vec)