[SciPy-user] Selecting array elements using other array

Johannes Loehnert a.u.r.e.l.i.a.n at gmx.net
Fri Sep 22 03:34:26 CDT 2006

On Friday 22 September 2006 10:27, Jose Luis Gomez Dans wrote:
> Hi!
> For the time being, I am still trapped with Numeric, and an old-ish version
> of Enthought. i am aware that with numpy, this question is trivial, but I
> need to keep using this version of Enthought.
> Essentially, I have two arrays: one is X (shape Nxd), and the other is id
> (shape N). I want to get an array which give me the rows of X where id is
> equal to some value. I can do this with for loops, but it is quite slow. I
> am sure there must be a way to do this efficiently. Note that d can vary.

result = take(X, nonzero(id==value))

might be what you are looking for.

HTH, Johannes

More information about the SciPy-user mailing list