Last active
August 29, 2015 13:57
-
-
Save beny/9617633 to your computer and use it in GitHub Desktop.
Singular Value Decomposion - Ruby's GSL vs Python's NumPy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# in Ruby with GSL | |
>> m | |
=> GSL::Matrix | |
[ 1.000e+00 -1.000e+00 | |
1.000e+00 0.000e+00 | |
1.000e+00 1.000e+00 ] | |
>> m.svd | |
=> [GSL::Linalg::SV::UMatrix | |
[ -5.774e-01 7.071e-01 | |
-5.774e-01 0.000e+00 | |
-5.774e-01 -7.071e-01 ], GSL::Linalg::SV::VMatrix | |
[ -1.000e+00 -0.000e+00 | |
-0.000e+00 -1.000e+00 ], GSL::Linalg::SV::SingularValues | |
[ 1.732e+00 1.414e+00 ]] | |
# in Python with numpy | |
>>> y | |
matrix([[ 1, -1], | |
[ 1, 0], | |
[ 1, 1]]) | |
>>> np.linalg.svd(y) | |
(matrix([[ -5.77350269e-01, 7.07106781e-01, 4.08248290e-01], | |
[ -5.77350269e-01, 5.55111512e-17, -8.16496581e-01], | |
[ -5.77350269e-01, -7.07106781e-01, 4.08248290e-01]]), array([ 1.73205081, 1.41421356]), matrix([[-1., -0.], | |
[-0., -1.]])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment