assigning to matrix elements in NumPy

Fernando Perez fperez528 at yahoo.com
Wed Mar 12 06:23:06 CET 2003


Blair Hall wrote:

> I have just upgraded from NumPy 21 to NumPy 23 and was
> surprised to find that my matrix assignment doesn't work like it
> used to.
> 
> For example:
> 
>>>> from Matrix import *
>>>> m = Matrix( [[1,2],[3,4]])
>>>> m[1,1]
> 4
>>>> m[1,1] = 2
> Traceback (most recent call last):
>   File "<interactive input>", line 1, in ?
>   File "C:\PYTHON22\lib\site-packages\Numeric\Matrix.py", line 183, in
> __setitem__
>     value = value[0,0]
> IndexError: invalid index
>>>>
> 
> Apparently, I should have written
>>>> m[1,1] = Matrix( 2 )
> 
> Is this really indended, or am I confused?

Just to provide you with a reference point, the above code produces the same
error under Numpy 22.0.  Now, I've never used the Matrix class, only
regular arrays, so I can't say what the rationale is.  But that behavior
definitely looks most bizarre and counter-intuitive to me.  

You should ask in the numpy mailing list.

Cheers,

f.




More information about the Python-list mailing list