problem with svd in numpy

Zeynep Gerek Zeynep.Gerek at asu.edu
Thu Nov 2 13:51:35 EST 2006


Hello,
I am having weird problem with svd routine in python. I am comparing
eigenvector values from python and matlab. And they are giving different
values. Actually, they are same but python gives negative values of
these numbers.
 
This is my test program (I am dealing with 100x100 matrices) with the
array I used in matlab.
 
from numpy import*
a=zeros((10,10))
a=array([
[6,-1,-1,-1,-1,-1,-1,0,0,0],
[-1,7,-1,-1,-1,-1,-1,-1,0,0],
[-1,-1,7,-1,-1,-1,-1,-1,0,0],
[-1,-1,-1,6,-1,-1,-1,0,0,0],
[-1,-1,-1,-1,6,-1,-1,0,0,0],
[-1,-1,-1,-1,-1,8,-1,-1,-1,0],
[-1,-1,-1,-1,-1,-1,9,-1,-1,-1],
[0,-1,-1,0,0,-1,-1,6,-1,-1],
[0,0,0,0,0,-1,-1,-1,4,-1],
[0,0,0,0,0,0,-1,-1,-1,3]])   
u,w,vt = linalg.svd(a)
print u
 
Output:
u
array([[ -1.05409255e-01,   1.48045079e-01,  -2.22322513e-01,
          3.54544091e-15,   3.70413913e-01,  -7.27640158e-01,
          2.60327955e-01,   1.08243955e-01,  -2.67189407e-01,
          3.16227766e-01],
       [ -1.05409255e-01,   8.51968962e-02,   5.37745352e-01,
          7.07106781e-01,   4.44089210e-16,   3.88578059e-15,
         -2.31331268e-01,   4.16676907e-02,  -1.92898838e-01,
          3.16227766e-01],
       [ -1.05409255e-01,   8.51968962e-02,   5.37745352e-01,
         -7.07106781e-01,  -1.06858966e-15,  -3.05311332e-15,
         -2.31331268e-01,   4.16676907e-02,  -1.92898838e-01,
          3.16227766e-01],
       [ -1.05409255e-01,   1.48045079e-01,  -2.22322513e-01,
         -3.52416288e-15,   4.44947906e-01,   6.84607937e-01,
          2.60327955e-01,   1.08243955e-01,  -2.67189407e-01,
          3.16227766e-01],
       [ -1.05409255e-01,   1.48045079e-01,  -2.22322513e-01,
          1.16652940e-15,  -8.15361818e-01,   4.30322209e-02,
          2.60327955e-01,   1.08243955e-01,  -2.67189407e-01,
          3.16227766e-01],
       [ -1.05409255e-01,  -9.20330077e-01,  -1.07260256e-01,
          1.88817436e-15,   1.11022302e-16,  -3.33066907e-16,
         -4.57953818e-02,  -1.32746681e-01,  -1.03236512e-01,
          3.16227766e-01],
       [  9.48683298e-01,   7.14706072e-16,  -1.04777298e-15,
          3.61617704e-16,  -8.32667268e-17,  -1.52655666e-16,
         -2.08166817e-16,  -9.36750677e-17,   1.42247325e-16,
          3.16227766e-01],
       [ -1.05409255e-01,   2.15015734e-01,  -4.92200980e-01,
         -1.55431223e-15,   4.85722573e-16,  -2.77555756e-16,
         -7.46027799e-01,  -1.27670308e-01,   1.65946178e-01,
          3.16227766e-01],
       [ -1.05409255e-01,   1.51153561e-01,   1.21762878e-01,
          1.66533454e-15,   1.80411242e-16,   3.46944695e-16,
          3.33969907e-01,  -7.50787335e-01,   4.19520882e-01,
          3.16227766e-01],
       [ -1.05409255e-01,  -6.03682488e-02,   6.91751920e-02,
         -1.23512311e-15,  -2.28983499e-16,   2.08166817e-17,
          1.39531945e-01,   6.03137078e-01,   7.05135347e-01,
          3.16227766e-01]])
 
Matlab output:
 
u =
 
    0.1054   -0.1480    0.2223   -0.0000    0.0000    0.8165    0.2603
0.1082   -0.2672    0.3162
    0.1054   -0.0852   -0.5377    0.7071   -0.0000   -0.0000   -0.2313
0.0417   -0.1929    0.3162
    0.1054   -0.0852   -0.5377   -0.7071    0.0000   -0.0000   -0.2313
0.0417   -0.1929    0.3162
    0.1054   -0.1480    0.2223   -0.0000   -0.7071   -0.4082    0.2603
0.1082   -0.2672    0.3162
    0.1054   -0.1480    0.2223    0.0000    0.7071   -0.4082    0.2603
0.1082   -0.2672    0.3162
    0.1054    0.9203    0.1073    0.0000    0.0000   -0.0000   -0.0458
-0.1327   -0.1032    0.3162
   -0.9487    0.0000   -0.0000    0.0000   -0.0000   -0.0000   -0.0000
0.0000    0.0000    0.3162
    0.1054   -0.2150    0.4922    0.0000    0.0000    0.0000   -0.7460
-0.1277    0.1659    0.3162
    0.1054   -0.1512   -0.1218   -0.0000   -0.0000   -0.0000    0.3340
-0.7508    0.4195    0.3162
    0.1054    0.0604   -0.0692    0.0000    0.0000   -0.0000    0.1395
0.6031    0.7051    0.3162
 
I am not sure if svd in numpy has a problem or not. When I test this
matrix in matlab, eigenvector values are different, Any idea why I am
not getting exact results from both program?
Any input will be appreciated. 
 
Best,
Nevin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20061102/a93cfb8f/attachment.html>


More information about the Python-list mailing list