[SciPy-User] Matrix indexing and updating

Luca Manini manini.luca at tiscali.it
Mon Nov 1 06:52:42 EDT 2010


I'm sorry for the "half backed" reply ... a too fast C-c C-c :/

The missing part was an example of an ugly code that I find myself
writing too often in order to use a 1xN scipy array as a list (to
iterate or to access the entries a v[0], v[1], etc.):

    In [58]: import scipy

    In [59]: v = scipy.matrix(range(5))

    In [60]: v
    Out[60]: matrix([[0, 1, 2, 3, 4]])

    In [61]: for x in v: 
       ....:        print x
       ....: 
    [[0 1 2 3 4]]

    In [62]: 

    In [63]: z = v.tolist()[0]

    In [64]: z
    Out[64]: [0, 1, 2, 3, 4]

    In [65]: for x in z:
       ....:     print x
       ....:     
       ....: 
    0
    1
    2
    3
    4

I know that the problem probably is my inexperience with scipy and
that the (related) fact to use explicit iteration too often, but it is
still a problem anyway.

      TIA, Luca




More information about the SciPy-User mailing list