import numpy as np
# 打印A的函数
def pprint(msg, A):
print("---", msg, "---")
(n,m) = A.shape
for i in range(0, n):
line = ""
for j in range(0, m):
line += "{0:.2f}".format(A[i,j]) + "\t"
print(line)
print("")
print("特征值分解\n")
A = np.array([[3.0, 1.0], [2.0, 2.0]])
w, S = np.linalg.eig(A)
L = np.diag(w)
pprint("矩阵B ", A)
pprint("特征矩阵 L", L)
pprint("特征向量矩阵 S", S)
pprint("S*L*S^{-1}", np.matmul(np.matmul(S,L), np.linalg.inv(S)))
B = np.array([[1.0, 1.0, 0.0], [1.0, 3.0, 1.0], [2.0, -1.0, 1.0]])
w, S = np.linalg.eig(B)
L = np.diag(w)
pprint("矩阵B", B)
pprint("特征矩阵 L", L)
pprint("特征向量矩阵 S", S)
pprint("S*L*S^{-1}", np.matmul(np.matmul(S,L), np.linalg.inv(S)))
【线代&NumPy】 特征值分解
最新推荐文章于 2025-03-08 17:51:09 发布