[Numpy-discussion] Fwd: Getting subarray

Steve Lianoglou lists.steve@arachnedesign....
Mon Apr 23 10:44:08 CDT 2007


Hi,

On Apr 23, 2007, at 11:30 AM, Tommy Grav wrote:

> I have two arrays:
>
> a = numpy.array([0,1,2,3,4,5,6,7,8,9])
> b = numpy.array([0,0,1,1,2,2,0,1,2,3])
>
> I would like to get the part of a that corresponds
> to where b is equal to i.
>
> For example:
>
> i = 0 => ([0,1,6])
> i = 1 => ([2,3,7])

a[numpy.where(b == 0)]

and

a[numpy.where(b == 1)]

respectively will get you what you're after.


-steve




More information about the Numpy-discussion mailing list