更新
适用于scipy.sparse.linalg.eigs method
,但仍不适用于scipy.linalg.eigs
。
我有一个真正的正方矩阵,我试图找到它的第一个(最大的)特征向量。由于Perron-Frobenius定理,最大的特征向量应该具有所有正条目,但在我的情况下它不是。这是我构建矩阵的代码:
def build_adj_matrix(G):
matrix = np.zeros(shape=(34,34))
for i in range(0,34):
for j in range(0,34):
if j+1 in G.adj[i+1]:
matrix[i][j] = 1.00001
else:
matrix[i][j] = 0.00001
return matrix
这是我检索特征向量的代码:
from scipy import linalg as LA
...
M = build_adj_matrix(G)
evals, evecs = LA.eig(M)
print(evecs)
我的输出是:
[ 3.55489549e-01 +0.00000000e+00j 3.86861181e-01 +0.00000000e+00j
3.17170097e-01 +0.00000000e+00j 2.77301505e-01 +0.00000000e+00j
5.54686086e-01 +0.00000000e+00j -1.97848347e-01 +0.00000000e+00j
-1.71390654e-01 +0.00000000e+00j -1.42227261e-02 +0.00000000e+00j
1.87538203e-03 +0.00000000e+00j -6.71077427e-02 +0.00000000e+00j
5.93338345e-02 +0.00000000e+00j 3.80034428e-02 +0.00000000e+00j
-1.51430299e-01 +0.00000000e+00j -6.33215778e-02 +0.00000000e+00j
1.43005327e-01 +0.00000000e+00j -7.33049336e-02 +0.00000000e+00j
-1.64571850e-01 +0.00000000e+00j 5.91985880e-02 +0.00000000e+00j
-1.31441525e-01 +0.00000000e+00j 1.35954155e-01 +0.00000000e+00j
-2.30981270e-02 +0.00000000e+00j -1.86533000e-01 +0.00000000e+00j
7.84949962e-02 +0.00000000e+00j 9.41416444e-06 +0.00000000e+00j
-1.92116017e-17 +0.00000000e+00j 1.10600656e-16 +0.00000000e+00j
1.75023609e-17 -1.35088126e-17j 1.75023609e-17 +1.35088126e-17j
4.75348687e-17 +0.00000000e+00j -1.99584575e-18 +2.25485520e-17j
-1.99584575e-18 -2.25485520e-17j -6.78262748e-18 -8.13743189e-17j
-6.78262748e-18 +8.13743189e-17j 8.83354389e-17 +0.00000000e+00j]