方阵a的奇异值分解是A = U*S*V.T
。在
我们可以取A的n次方如下:A^3= U*S^3*V.T
下面是一些基本的python代码。在
import numpy as np
A = np.matrix('1 2; 3 4')
A_3rd = np.linalg.matrix_power(A,3)
assert np.array_equal(A_3rd, np.dot(A, np.dot(A,A)) )
# svd for A
U,s,V = np.linalg.svd(A)
S = np.zeros(A.shape); S[:2,:2]= np.diag(s) # fill diagonals
S = np.asmatrix(S) # convert from array to matrix
print U.shape, S.shape, V.shape # print shapes
A_3rd_by_SVD =np.dot(U, np.dot(np.linalg.matrix_power(S, 3),V))
但是我得到的值与numpy.linalg_matrix_幂(). 有人能解释一下为什么会这样吗?在
^{pr2}$
目前没有回答
相关问题 更多 >
编程相关推荐