[Numpy-discussion] matrix indexing question

Sven Schreiber svetosch@gmx....
Mon Mar 26 08:48:08 CDT 2007


Alan G Isaac schrieb:

> 
> What feels wrong: iterating over a container does not give 
> access to the contained objects.  This is not Pythonic.

If you iterate over the rows of the matrix, it feels natural to me to
get the row vectors -- and as you know a 1d-array does not contain the
information of "row-ness", so you need to get a 2d thing to properly
return those "contained objects". So in my view the current behavior
actually does exactly what you're calling for.

(But I admit I'm a 2d fan so much so that I didn't even know that using
a single index is possible with a matrix. I thought one always had to be
explicit about both dimensions... So thanks for pointing this out.
-- BTW, I'm aware that sticking to numpy-matrices exclusively is not
possible. For example, eigenvalues are returned in a 1d-array even if
you pass a matrix, and it's intended behavior.)

cheers,
sven





More information about the Numpy-discussion mailing list