[Numpy-discussion] addressing a submatrix
Martin Wiechert
martin.wiechert at gmx.de
Wed Jun 14 10:19:35 EDT 2006
Thanks Pau, that's exactly what I was looking for.
Martin
On Wednesday 14 June 2006 12:01, you wrote:
> 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 (I_1,
> > J_1), (I_2, J_2). 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
More information about the NumPy-Discussion
mailing list