[SciPy-user] extracting a range from within an array

Alan G Isaac aisaac at american.edu
Tue May 16 10:15:05 EDT 2006


On Tue, 16 May 2006, Chris Fonnesbeck apparently wrote: 
> foo = arange(100) bar = foo.compress(foo>40) 
> However, you cannot do the same for a chunk in the middle: 
> bar.foo.compress(20<foo<40) 

One simple way below.

Cheers,
Alan Isaac 

>>> x = N.arange(100)
>>> x[(x>20)*(x<40)]
array([21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39])






More information about the SciPy-User mailing list