[Numpy-discussion] a==b for numpy arrays

Christopher Barker Chris.Barker at noaa.gov
Mon Dec 11 18:35:54 CST 2006


Steve Lianoglou wrote:
>> a[where(a < 0)] = 0

> Ah ... I see, w/o the where returns a boolean array. I reckon that's  
> actually better to use than the where clause for cases like this  
> since (for one) it'll take up less memory than arrays of ints.

not to mention that you're creating an entire temporary array for no 
reason when you use were. the above statement creates a boolean array 
for a < 10, then creates another array with the where statement. Where 
is very handy when you want a new array, created according to some 
element-wise condition:

b = where(a > 0, 10, 0)

-Chris



-- 
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at noaa.gov


More information about the Numpy-discussion mailing list