【发布时间】:2021-01-02 03:58:38
【问题描述】:
我正在使用 Python 导出与 3x3 矩阵中的特征值相关的特征向量。我的代码返回正确的特征值但错误的特征向量。
A = np.array([[-2, -4, 2],
[-2, 1, 2],
[4, 2, 5]])
print (A)
print ('-------------------------------------------------------')
eigenvalues, eigenvectors = np.linalg.eig(A) # must use this line of code exactly
print(f'eigenvalues of matrix A are:{eigenvalues}')
print ('-------------------------------------------------------')
print(f'eigenvectors of matrix A are:{eigenvectors}')
例如,与值 6 关联的特征向量应该是 [1, 6, 16],而不是代码输出的内容。
【问题讨论】:
-
每个特征值有无限多个特征向量。代码工作正常。
-
从 numpy 文档中,返回特征值矩阵,使得“归一化(单位“长度”)特征向量,使得列 v[:,i] 是对应于特征值 w[一世]。”查看特征向量矩阵的最后 列。它是 [1, 6, 16],仅归一化。
标签: python linear-algebra eigenvalue eigenvector