numpy array, strangeness

Stephane Jolicoeur akhar at videotron.ca
Thu Feb 27 21:40:49 CET 2003


Hello,
I am trying to work with LinearAlgebra.py, it works but Numpy won't let 
me do the reverse equation.
I have an array q that is 12 by 9 then use LinearAlgebra's 
singular_value_decomposition on it and get back 3 arrays T , S and D. 
Now q should be the product of T*S*D, so I do this in the shell and get 
a ValueError: frames are not aligned. Why is this? what can I do?
I just downloaded numpy from sourceforge it's the latest release. I am 
using it under OS X, everything seems install correctly.

Best regards

Stephane

PS: here is an exerpt of my tries in the python shell

 >>> q
array([[1, 0, 0, 1, 0, 0, 0, 0, 0],
        [1, 0, 1, 0, 0, 0, 0, 0, 0],
        [1, 1, 0, 0, 0, 0, 0, 0, 0],
        [0, 1, 1, 0, 1, 0, 0, 0, 0],
        [0, 1, 1, 2, 0, 0, 0, 0, 0],
        [0, 1, 0, 0, 1, 0, 0, 0, 0],
        [0, 1, 0, 0, 1, 0, 0, 0, 0],
        [0, 0, 1, 1, 0, 0, 0, 0, 0],
        [0, 1, 0, 0, 0, 0, 0, 0, 1],
        [0, 0, 0, 0, 0, 1, 1, 1, 0],
        [0, 0, 0, 0, 0, 0, 1, 1, 1],
        [0, 0, 0, 0, 0, 0, 0, 1, 1]])
 >>> T,S,D = la.singular_value_decomposition(q)
 >>> T*S*D
Traceback (most recent call last):
   File "<stdin>", line 1, in ?
ValueError: frames are not aligned
 >>> T*D
Traceback (most recent call last):
   File "<stdin>", line 1, in ?
ValueError: frames are not aligned
 >>> D
array([[ -1.97392802e-01,  -6.05990269e-01,  -4.62917508e-01, 
-5.42114417e-01,
               -2.79469108e-01,  -3.81521297e-03,  -1.46314675e-02, 
-2.41368353e-02,
               -8.19573680e-02],
        [ -5.59135178e-02,   1.65592878e-01,  -1.27312062e-01, 
-2.31755229e-01,
                1.06774717e-01,   1.92847936e-01,   4.37874883e-01, 
6.15121899e-01,
                5.29937072e-01],
        [  1.10269729e-01,  -4.97326494e-01,   2.07605953e-01, 
5.69921445e-01,
               -5.05449907e-01,   9.81842398e-02,   1.92955572e-01, 
2.52903979e-01,
                7.92731465e-02],
        [ -9.49785024e-01,  -2.86488989e-02,   4.16091951e-02, 
2.67714038e-01,
                1.50035433e-01,   1.50814907e-02,   1.55071875e-02, 
1.01990092e-02,
               -2.45549056e-02],
        [  4.56785564e-02,  -2.06327278e-01,   3.78336233e-01, 
-2.05604711e-01,
                3.27194409e-01,   3.94841214e-01,   3.49485348e-01, 
1.49798472e-01,
               -6.01992995e-01],
        [ -7.65935585e-02,  -2.56475221e-01,   7.24399642e-01, 
-3.68860901e-01,
                3.48130498e-02,  -3.00161116e-01,  -2.12201424e-01, 
9.74341694e-05,
                3.62218973e-01],
        [ -1.77318297e-01,   4.32984245e-01,   2.36889703e-01, 
-2.64799523e-01,
               -6.72303530e-01,   3.40839827e-01,   1.52194722e-01, 
-2.49145920e-01,
               -3.80341889e-02],
        [  1.43932591e-02,  -4.93053257e-02,  -8.82550205e-03, 
1.94669439e-02,
                5.83495626e-02,  -4.54476523e-01,   7.61527011e-01, 
-4.49642757e-01,
                6.96375497e-02],
        [  6.36922896e-02,  -2.42782900e-01,  -2.40768748e-02, 
8.42069017e-02,
                2.62375876e-01,   6.19847194e-01,  -1.79751825e-02, 
-5.19890498e-01,
                4.53506755e-01]])
 >>> T
array([[ -2.21350778e-01,  -1.13179617e-01,   2.88958154e-01, 
-4.14750740e-01,
               -1.06275121e-01,  -3.40983324e-01,  -5.22657771e-01, 
6.04501376e-02,
                4.06677509e-01],
        [ -1.97645401e-01,  -7.20877788e-02,   1.35039639e-01, 
-5.52239584e-01,
                2.81768939e-01,   4.95878011e-01,   7.04234412e-02, 
9.94003721e-03,
                1.08930266e-01],
        [ -2.40470226e-01,   4.31519521e-02,  -1.64429079e-01, 
-5.94961818e-01,
               -1.06755285e-01,  -2.54955130e-01,   3.02240236e-01, 
-6.23280150e-02,
               -4.92444364e-01],
        [ -4.03598863e-01,   5.70702584e-02,  -3.37803538e-01, 
9.91137295e-02,
                3.31733718e-01,   3.84831917e-01,  -2.87217529e-03, 
3.90504202e-04,
               -1.23293479e-02],
        [ -6.44481152e-01,  -1.67301206e-01,   3.61148151e-01, 
3.33461601e-01,
               -1.58954979e-01,  -2.06522588e-01,   1.65828575e-01, 
-3.42720233e-02,
               -2.70696289e-01],
        [ -2.65037470e-01,   1.07159573e-01,  -4.25998497e-01, 
7.38121922e-02,
                8.03193764e-02,  -1.69676389e-01,  -2.82915727e-01, 
1.61465472e-02,
                5.38746887e-02],
        [ -2.65037470e-01,   1.07159573e-01,  -4.25998497e-01, 
7.38121922e-02,
                8.03193764e-02,  -1.69676389e-01,  -2.82915727e-01, 
1.61465472e-02,
                5.38746887e-02],
        [ -3.00828164e-01,  -1.41270468e-01,   3.30308435e-01, 
1.88091918e-01,
                1.14784622e-01,   2.72155276e-01,  -3.29941102e-02, 
1.89980144e-02,
                1.65339170e-01],
        [ -2.05917861e-01,   2.73647431e-01,  -1.77597017e-01, 
-3.23519366e-02,
               -5.37150003e-01,   8.09439782e-02,   4.66897525e-01, 
3.62988295e-02,
                5.79426106e-01],
        [ -1.27461830e-02,   4.90161792e-01,   2.31120155e-01, 
2.48019985e-02,
                5.94169516e-01,  -3.92125064e-01,   2.88317461e-01, 
-2.54567945e-01,
                2.25424069e-01],
        [ -3.61358490e-02,   6.22785235e-01,   2.23086363e-01, 
7.00072121e-04,
               -6.82529382e-02,   1.14908954e-01,  -1.59575477e-01, 
6.81125438e-01,
               -2.31961226e-01],
        [ -3.17563289e-02,   4.50508919e-01,   1.41115164e-01, 
-8.72947061e-03,
               -3.00495110e-01,   2.77343397e-01,  -3.39495286e-01, 
-6.78417879e-01,
               -1.82534976e-01]])
 >>> d[:1,:1]
Traceback (most recent call last):
   File "<stdin>", line 1, in ?
NameError: name 'd' is not defined
 >>> D[:1,1:]
array([       [-0.60599027, -0.46291751, -0.54211442, -0.27946911, 
-0.00381521, -0.01463147,
              -0.02413684, -0.08195737]])
 >>> Sh
(array([[ 3.34088375,  0.        ,  0.        ,  0.        ,  0. 
,  0.        ,
               0.        ,  0.        ,  0.        ],
        [ 0.        ,  2.541701  ,  0.        ,  0.        ,  0. 
,  0.        ,
               0.        ,  0.        ,  0.        ],
        [ 0.        ,  0.        ,  2.35394352,  0.        ,  0. 
,  0.        ,
               0.        ,  0.        ,  0.        ],
        [ 0.        ,  0.        ,  0.        ,  1.64453229,  0. 
,  0.        ,
               0.        ,  0.        ,  0.        ],
        [ 0.        ,  0.        ,  0.        ,  0.        , 
1.50483155,  0.        ,
               0.        ,  0.        ,  0.        ],
        [ 0.        ,  0.        ,  0.        ,  0.        ,  0. 
,  1.30638195,
               0.        ,  0.        ,  0.        ],
        [ 0.        ,  0.        ,  0.        ,  0.        ,  0. 
,  0.        ,
               0.84590308,  0.        ,  0.        ],
        [ 0.        ,  0.        ,  0.        ,  0.        ,  0. 
,  0.        ,
               0.        ,  0.56013442,  0.        ],
        [ 0.        ,  0.        ,  0.        ,  0.        ,  0. 
,  0.        ,
               0.        ,  0.        ,  0.36367684]]), (2, 2))
 >>> sh = Sh[:2,:2]
Traceback (most recent call last):
   File "<stdin>", line 1, in ?
TypeError: tuple indices must be integers
 >>> Sh[:2,:2]
Traceback (most recent call last):
   File "<stdin>", line 1, in ?
TypeError: tuple indices must be integers
 >>> Sh[:1,1:
... ]
Traceback (most recent call last):
   File "<stdin>", line 1, in ?
TypeError: tuple indices must be integers
 >>> Sh[:2,2:]
Traceback (most recent call last):
   File "<stdin>", line 1, in ?
TypeError: tuple indices must be integers
 >>> D[:2,:2]
array([[-0.1973928 , -0.60599027],
        [-0.05591352,  0.16559288]])
 >>> D[:12,:2]
array([[-0.1973928 , -0.60599027],
        [-0.05591352,  0.16559288],
        [ 0.11026973, -0.49732649],
        [-0.94978502, -0.0286489 ],
        [ 0.04567856, -0.20632728],
        [-0.07659356, -0.25647522],
        [-0.1773183 ,  0.43298424],
        [ 0.01439326, -0.04930533],
        [ 0.06369229, -0.2427829 ]])
 >>> d = D[:12,:2]
 >>> T
array([[ -2.21350778e-01,  -1.13179617e-01,   2.88958154e-01, 
-4.14750740e-01,
               -1.06275121e-01,  -3.40983324e-01,  -5.22657771e-01, 
6.04501376e-02,
                4.06677509e-01],
        [ -1.97645401e-01,  -7.20877788e-02,   1.35039639e-01, 
-5.52239584e-01,
                2.81768939e-01,   4.95878011e-01,   7.04234412e-02, 
9.94003721e-03,
                1.08930266e-01],
        [ -2.40470226e-01,   4.31519521e-02,  -1.64429079e-01, 
-5.94961818e-01,
               -1.06755285e-01,  -2.54955130e-01,   3.02240236e-01, 
-6.23280150e-02,
               -4.92444364e-01],
        [ -4.03598863e-01,   5.70702584e-02,  -3.37803538e-01, 
9.91137295e-02,
                3.31733718e-01,   3.84831917e-01,  -2.87217529e-03, 
3.90504202e-04,
               -1.23293479e-02],
        [ -6.44481152e-01,  -1.67301206e-01,   3.61148151e-01, 
3.33461601e-01,
               -1.58954979e-01,  -2.06522588e-01,   1.65828575e-01, 
-3.42720233e-02,
               -2.70696289e-01],
        [ -2.65037470e-01,   1.07159573e-01,  -4.25998497e-01, 
7.38121922e-02,
                8.03193764e-02,  -1.69676389e-01,  -2.82915727e-01, 
1.61465472e-02,
                5.38746887e-02],
        [ -2.65037470e-01,   1.07159573e-01,  -4.25998497e-01, 
7.38121922e-02,
                8.03193764e-02,  -1.69676389e-01,  -2.82915727e-01, 
1.61465472e-02,
                5.38746887e-02],
        [ -3.00828164e-01,  -1.41270468e-01,   3.30308435e-01, 
1.88091918e-01,
                1.14784622e-01,   2.72155276e-01,  -3.29941102e-02, 
1.89980144e-02,
                1.65339170e-01],
        [ -2.05917861e-01,   2.73647431e-01,  -1.77597017e-01, 
-3.23519366e-02,
               -5.37150003e-01,   8.09439782e-02,   4.66897525e-01, 
3.62988295e-02,
                5.79426106e-01],
        [ -1.27461830e-02,   4.90161792e-01,   2.31120155e-01, 
2.48019985e-02,
                5.94169516e-01,  -3.92125064e-01,   2.88317461e-01, 
-2.54567945e-01,
                2.25424069e-01],
        [ -3.61358490e-02,   6.22785235e-01,   2.23086363e-01, 
7.00072121e-04,
               -6.82529382e-02,   1.14908954e-01,  -1.59575477e-01, 
6.81125438e-01,
               -2.31961226e-01],
        [ -3.17563289e-02,   4.50508919e-01,   1.41115164e-01, 
-8.72947061e-03,
               -3.00495110e-01,   2.77343397e-01,  -3.39495286e-01, 
-6.78417879e-01,
               -1.82534976e-01]])
 >>> t = T[:2,:9]
 >>> t
array([[-0.22135078, -0.11317962,  0.28895815, -0.41475074, -0.10627512, 
-0.34098332,
              -0.52265777,  0.06045014,  0.40667751],
        [-0.1976454 , -0.07208778,  0.13503964, -0.55223958, 
0.28176894,  0.49587801,
               0.07042344,  0.00994004,  0.10893027]])
 >>> t*d
Traceback (most recent call last):
   File "<stdin>", line 1, in ?
ValueError: frames are not aligned
 >>> d*t
Traceback (most recent call last):
   File "<stdin>", line 1, in ?
ValueError: frames are not aligned
 >>> t.shape()
Traceback (most recent call last):
   File "<stdin>", line 1, in ?
TypeError: 'tuple' object is not callable
 >>> t
array([[-0.22135078, -0.11317962,  0.28895815, -0.41475074, -0.10627512, 
-0.34098332,
              -0.52265777,  0.06045014,  0.40667751],
        [-0.1976454 , -0.07208778,  0.13503964, -0.55223958, 
0.28176894,  0.49587801,
               0.07042344,  0.00994004,  0.10893027]])
 >>> s
Traceback (most recent call last):
   File "<stdin>", line 1, in ?
NameError: name 's' is not defined
 >>> d
array([[-0.1973928 , -0.60599027],
        [-0.05591352,  0.16559288],
        [ 0.11026973, -0.49732649],
        [-0.94978502, -0.0286489 ],
        [ 0.04567856, -0.20632728],
        [-0.07659356, -0.25647522],
        [-0.1773183 ,  0.43298424],
        [ 0.01439326, -0.04930533],
        [ 0.06369229, -0.2427829 ]])
 >>> d.shape
(9, 2)
 >>> t.shape
(2, 9)
 >>> d*t
Traceback (most recent call last):
   File "<stdin>", line 1, in ?
ValueError: frames are not aligned
 >>> reshape(d, (9,2))
array([[-0.1973928 , -0.60599027],
        [-0.05591352,  0.16559288],
        [ 0.11026973, -0.49732649],
        [-0.94978502, -0.0286489 ],
        [ 0.04567856, -0.20632728],
        [-0.07659356, -0.25647522],
        [-0.1773183 ,  0.43298424],
        [ 0.01439326, -0.04930533],
        [ 0.06369229, -0.2427829 ]])
 >>> d = reshape(d,(9,2))
 >>> t.shape
(2, 9)
 >>> t = reshape(t,(2,9))
 >>> d*t
Traceback (most recent call last):
   File "<stdin>", line 1, in ?
ValueError: frames are not aligned
 >>>





More information about the Python-list mailing list