svd分解和svd近似

SVD近似:
M m n U m k S k k ( V T ) k n M_{m·n}≈U_{m·k}S_{k·k}(V^T)_{k·n}

SVD分解:
M m n U m m S m n ( V T ) n n M_{m·n}≈U_{m·m}S_{m·n}(V^T)_{n·n}

代码如下:

#-*- coding:utf-8 -*-
import sys
reload(sys)
from numpy import *
import numpy as np
sys.setdefaultencoding("utf-8")

data = mat([[1,2,3,4,5,6,7,8,9],
                [5,6,7,8,9,0,8,6,7],
                [9,0,8,7,1,4,3,2,1],
                [6,4,2,1,3,4,2,1,5]])
print"data的维度:",np.shape(data)
U,sigma,VT = np.linalg.svd(data,full_matrices=False)
print"-----------------1-U----------------------"
print U
print np.shape(U)
print"-----------------1-Σ-----------------------"
print sigma
print np.shape(sigma)
print"------------------1-VT---------------------"
print VT
print np.shape(VT)
print"##########################################################"
print"------------------2-U---------------------"
U,sigma,VT = np.linalg.svd(data,full_matrices=True)
print U
print np.shape(U)
print"-------------------2---------------------"
print sigma
print np.shape(sigma)
print"-------------------2-VT--------------------"
print VT
print np.shape(VT)

猜你喜欢

转载自blog.csdn.net/appleyuchi/article/details/88664686
SVD