[SciPy-User] Matrix indexing and updating

Luca Manini manini.luca at tiscali.it
Mon Nov 1 06:43:53 EDT 2010


>>>>> "Emanuele" == Emanuele Olivetti <emanuele at relativita.com> writes:

    Emanuele> Hi Luca, If I understand you problem correctly, maybe
    Emanuele> this example can help you:

    It helps a little, but:

    1) you are using numpy.ndarray instead of scipy.matrix.  I have
       not grasped the difference yet, apart for the annoying fact
       that a 1xN matrix is not a vector and still has two indices
       (and that makes the code less "explicit").

       For exmple:

    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


    2) you set the submatrix values to 1, but what I need is to "add"
       to the submatrix the values that come from an (equal sized)
       matrix.




More information about the SciPy-User mailing list