In [1]:
import numpy as np
import numpy.linalg as la
In [3]:
X = np.random.randn(3,3)
In [10]:
U, singvals, VT = la.svd(X)
V = VT.T
Sigma = np.diag(singvals)
In [11]:
print(U)
print(Sigma)
print(V)
[[ 0.70141991  0.71111889  0.04816667]
 [-0.11244725  0.17713952 -0.97774087]
 [-0.70382222  0.68039071  0.20421255]]
[[ 2.17779831  0.          0.        ]
 [ 0.          0.78570126  0.        ]
 [ 0.          0.          0.53790665]]
[[ 0.17812518 -0.86278717 -0.47314872]
 [ 0.20749616  0.50296027 -0.83903296]
 [-0.96188189 -0.05127635 -0.26861491]]

In [12]:
X - U.dot(Sigma).dot(V.T)
Out[12]:
array([[ -2.49800181e-16,   3.33066907e-16,  -2.22044605e-16],
       [  1.80411242e-16,   2.22044605e-16,   0.00000000e+00],
       [ -4.44089210e-16,   2.77555756e-16,  -2.22044605e-16]])
In [13]:
U2 = U.copy()
U2[:, 0] *= -1
V2 = V.copy()
V2[:, 0] *= -1
In [14]:
X - U2.dot(Sigma).dot(V2.T)
Out[14]:
array([[ -2.49800181e-16,   3.33066907e-16,  -2.22044605e-16],
       [  1.80411242e-16,   2.22044605e-16,   0.00000000e+00],
       [ -4.44089210e-16,   2.77555756e-16,  -2.22044605e-16]])
In [11]:
 
In [11]:
 
In [11]:
 
In []: