Jorl Shefner wrote:
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.
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.
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]
mask= where((data > 3),1,0)
result= compress(mask,data)
result
data= arange(10)
data= [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
mask= where((data > 3),1,0)
result= compress(mask,data)
result
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.
false and true, respectively. You don't need where() at all.
Try
mask = logical_and(3 < data, data <= 7)
--
Robert Kern
rkern at ucsd.edu
"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter