马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
import numpy as np
data = np.array([[5,0,3],[3,-5,4]])
dataT = np.transpose (data)
datadataT = data@dataT
eigen_value,U=np.linalg.eigh(datadataT)
evall_sort_idx = np.argsort(eigen_value)[::-1]
eigen_value = np.sort(eigen_value)[::-1]
U = U[:,evall_sort_idx]
sigma = np.mat(np.diag(np.sqrt(eigen_value)))
inverse_sigma = np.linalg.inv(sigma)
UT = np.transpose(U)
VT= inverse_sigma@UT@data
print('U')
print(U)
A = U@sigma@VT
print('A')
print(A)
U1,sigmal,VT1 = np.linalg.svd(data)
print('U1')
print(U1)
print(eigen_value)
print(sigma)
print(sigmal)
|