FAQ
Could anyone tell me the efficient way to do this? Extracting values
from an array for a single condition (say all values greater than 'x')
using 'where' and 'compress' is simple enough.
from Numeric import arange,where,compress
data= arange(10)
data= [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
result
array([4, 5, 6, 7, 8, 9])

But, 'where' doesn't appear to allow for multiple conditions in one
statement. For instance, I'd like to do something like:

mask= where((3 < data <= 7),1,0)

but, this won't work.

So, the best I could come up with was this more complicated process that
requires 2 separate masks and an extra temporary array.
array([0, 0, 0, 0, 4, 5, 6, 7, 8, 9])
array([0, 0, 0, 0, 4, 5, 6, 7, 0, 0])
r
array([4, 5, 6, 7])

Is there a more concise way?

Thanks,

J.S.

## Related Discussions

 view thread | post posts ‹ prev | 1 of 3 | next ›
Discussion Overview
 group python-list categories python posted Nov 29, '04 at 11:05p active Nov 30, '04 at 2:48p posts 3 users 2 website python.org

### 2 users in discussion

Content

People

Support

Translate

site design / logo © 2022 Grokbase