[SciPy-user] syntax for indexing

Michael Hearne mhearne@usgs....
Fri Nov 7 11:32:35 CST 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@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