Matlab-style mask in Python??
uwe at rocksport.de
Tue Oct 30 13:22:02 CET 2001
Ozone Hole near South Pole <ozonehole2k at yahoo.com> wrote:
| I am a long time Matlab user. I just picked up Python for a short
| I wonder what should be the best way to do sth like:
| idx=a>4 ans: [0,0,1,1,0,1,0,0,0]
| a(idx) ans: [6,7,54]
| idx=map(lambda x: x>4,a) #assume this calculation is lengthy
| #and we don't want to repeat
| last cmd???
| While we can always put that into a for loop, then append the ans
| element-by-element.... I feel there should be an easier way in
| Any suggestions?
have a look at Numerical Python http://www.numpy.org. I think it
will help you.
Uwe.Schmitt at num.uni-sb.de Universität des Saarlandes
phone: +49 (0)681/302-2468 Geb. 36.1, Zi. 4.17, PF 151150
More information about the Python-list