[Numpy-discussion] Re: where

Johannes Loehnert a.u.r.e.l.i.a.n at gmx.net
Tue Apr 18 01:46:04 CDT 2006


On Thursday 13 April 2006 19:16, Ryan Krauss wrote:
> which makes this:
> myvect=where((f>19.5) & (f<38) &
> (phase>0),ones(shape(phase)),zeros(shape(phase)))
>
> actually really silly, sense all it is a complicated way to get back
> the input of
> (f>19.5) & (f<38) & (phase>0)
>

...but you should cast the second to signed int32, otherwise

a = (f>19.5) & (f<38) & (phase>0)
print a-1

will give an array of 0's and 255's :) (since boolean arrays are by default 
upcast to unsigned int8)

Johannes




More information about the Numpy-discussion mailing list