[Numpy-discussion] addressing a submatrix (original) (raw)
Pau Gargallo pau.gargallo at gmail.com
Wed Jun 14 06:02:06 EDT 2006
- Previous message (by thread): [Numpy-discussion] addressing a submatrix
- Next message (by thread): [Numpy-discussion] numpy.test() fails on Redhat Enterprise and Solaris
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 6/14/06, Martin Wiechert <Martin.Wiechert at mpimf-heidelberg.mpg.de> wrote:
Hi Simon,
thanks for your reply. A [I, J] seems to only work if the indices are strides as in your example. I need fancy indices (like I = (1,3,4), J = (0,3,5)), and for them A [I, J] won't do what I want. As you can see from the example session I posted it does not address the whole rectangle IxJ but only the elements (I1, J1), (I2, J2). E.g., if I==J this is the diagonal of the submatrix, not the full submatrix.
you can use A[ ix_(I,J) ] to do what you want.
But, if you just want subrectangular regions then A[1:4,1:4] is enough. Please note that A[1:4,1:4] is not the same as A[ arange(1,4), arange(1,4) ], but is the same as A[ ix_(arange(1,4), arange(1,4)) ].
hope this heps pau
- Previous message (by thread): [Numpy-discussion] addressing a submatrix
- Next message (by thread): [Numpy-discussion] numpy.test() fails on Redhat Enterprise and Solaris
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]