[SciPy-user] selection from array

Francesc Alted faltet@pytables....
Mon Apr 6 05:58:39 CDT 2009


A Monday 06 April 2009, Eugene Semenko escrigué:
>     Hello! I'm new in Python and just started to learn it. My
> question is about method to make selection from array. Suppose there
> is an array: arr = np.arange(20,300,0.5)
> How can I select from this array elements where 30.5 < arr < 125?

arr[(arr > 30.5) & (arr < 125)]

This is a FAQ, so perhaps it would be worth if someone can add this 
example (a boolean composition of two conditions) to:

http://docs.scipy.org/doc/numpy/user/basics.indexing.html#boolean-or-mask-index-arrays

(or whatever place this is appropriate).

-- 
Francesc Alted

"One would expect people to feel threatened by the 'giant
brains or machines that think'.  In fact, the frightening
computer becomes less frightening if it is used only to
simulate a familiar noncomputer."

-- Edsger W. Dykstra
   "On the cruelty of really ting computer science"


More information about the SciPy-user mailing list