[SciPy-user] syntax for indexing

Michael Hearne mhearne at usgs.gov
Fri Nov 7 12:32:35 EST 2008


Assume that I have a setup like this:

from pylab import *
x = random((4,4))

I know how to get the indices of the values that are (for example), 
greater than 0.5:
i = (x > 0.5).nonzero()

How do I get the indices for those values in x that are greater than 0.5 
AND less than 0.8?

I tried:
i = (x > 0.5 && x < 0.8).nonzero()
i = (x > 0.5 & x < 0.8).nonzero()
i = (x > 0.5 and x < 0.8).nonzero()

to no avail.  Is this the wrong approach?

For Matlab users, the functionality which I am trying to replicate is:
x = rand(4,4);
i = find(x > 0.5 & x < 0.8);

Thanks,

Mike

-- 
------------------------------------------------------
Michael Hearne
mhearne at usgs.gov
(303) 273-8620
USGS National Earthquake Information Center
1711 Illinois St. Golden CO 80401
Senior Software Engineer
Synergetics, Inc.
------------------------------------------------------




More information about the SciPy-User mailing list