[SciPy-user] Selecting array elements using other array

Jose Luis Gomez Dans josegomez at gmx.net
Fri Sep 22 03:27:05 CDT 2006


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.

I have tried to build a new array and use compress or where. The new array has a new column with the id appended:
tmp=c_[X[:,0,NewAxis],X[:,1,NewAxis],X[:,2,NewAxis],id[:,NewAxis]]

However, this is just as messy, and i need to hard-code the second dimension of X.

There has to be a more elegant solution to this!!! 

Many thanks!
José
-- 
Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen! 
Ideal für Modem und ISDN: http://www.gmx.net/de/go/smartsurfer


More information about the SciPy-user mailing list