[SciPy-user] Selecting items from an array

Christian Kristukat ckkart at hoc.net
Tue Sep 27 10:19:19 CDT 2005


Noel O'Boyle wrote:
> Newbie question:
> 
> I'm trying to select items from a vector using a mask.
> 
> For example:
> X = array([100,56,44,99])
> mask = ([0,1,0,1])
> 
> I want to create:
> newX = array([56,99])
> i.e. only those elements of X for which mask is true.
> 
> scipy.take will do this but I need to find the indices of all of the 1's
> in mask. It must be possible to do this with scipy, but how?

compress(mask==1, X)

or use the MA (masked array) module of Numeric.

Regards, Christian



More information about the SciPy-user mailing list