Skip to content

Instantly share code, notes, and snippets.

@kyoro1
Created November 5, 2015 03:55
Show Gist options
  • Save kyoro1/44a2b4602f6109f6723a to your computer and use it in GitHub Desktop.
Save kyoro1/44a2b4602f6109f6723a to your computer and use it in GitHub Desktop.
Pythonで特異値分解してみる ref: http://qiita.com/kyoro1/items/4df11e933e737703d549
A=U\Sigma \overline{V^T}
A=\left(
\begin{matrix}
1 & 2 \\
3 & 4
\end{matrix}
\right)
> np.dot(V, V.T)
array([[ 1., 0.],
[ 0., 1.]])
> import numpy as np
> A = np.array([[1,2],[3,4]])
> A
array([[1, 2],
[3, 4]])
U, s, V = np.linalg.svd(A, full_matrices=True)
> U
array([[-0.40455358, -0.9145143 ],
[-0.9145143 , 0.40455358]])
> s
array([ 5.4649857 , 0.36596619])
> V
array([[-0.57604844, -0.81741556],
[ 0.81741556, -0.57604844]])
> np.diag(s)
array([[ 5.4649857 , 0. ],
[ 0. , 0.36596619]])
A=U\Sigma \overline{V^T}
>np.dot(np.dot(U, np.diag(s)),V)
array([[ 1., 2.],
[ 3., 4.]])
> np.dot(U, U.T)
array([[ 1.00000000e+00, 2.77555756e-16],
[ 2.77555756e-16, 1.00000000e+00]])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment