Torch和Numpy之——奇异值分解

输入

import torch
import numpy as np

#奇异值分解:把一个矩阵拆成3个矩阵

a = torch.tensor([[1.,2.],[3.,4.],[5.,6.]])
b = np.array([[1.,2.],[3.,4.],[5.,6.]])

#3*2:3*2,2*2(奇异值:对角阵),2*2
print(torch.svd(a))
#3*2:3*2,2*2(奇异值:对角阵,不足填充0),2*2
print(np.linalg.svd(b))

输出

torch.return_types.svd(
U=tensor([[-0.2298,  0.8835],
        [-0.5247,  0.2408],
        [-0.8196, -0.4019]]),
S=tensor([9.5255, 0.5143]),
V=tensor([[-0.6196, -0.7849],
        [-0.7849,  0.6196]]))
(array([[-0.2298477 ,  0.88346102,  0.40824829],
       [-0.52474482,  0.24078249, -0.81649658],
       [-0.81964194, -0.40189603,  0.40824829]]), array([9.52551809, 0.51430058]), array([[-0.61962948, -0.78489445],
       [-0.78489445,  0.61962948]]))

 

你可能感兴趣的:(Torch和Numpy之——奇异值分解)