[SciPy-user] scipy_core bug in where

Travis Oliphant oliphant at ee.byu.edu
Thu Nov 17 22:42:06 CST 2005


Ted Horst wrote:

>I have discovered a bug in the where function in scipy_core.
>
> >>> from scipy import array, int16, where
> >>> a = array([1,2,3,-32766,4,5,-32766,6], dtype = int16)
> >>> where(a != -32766, a, a.max())
>array([      65538,      229378,      262149,           6,       65538,
>             229378,           6, -2147352570])
>
>
>First, I was a little surprised that a.max() was type int32 rather than 
>int16 (which causes the result to have dtype int32), but then a is 
>clearly be misinterpreted.
>  
>
Thanks for catching the bug.   We'll look into it.

By the way,  you can reduce in the type int16 if you
need to using a.max(rtype=int16)  -- This was recently changed from
that default to avoid a different kind of surprise (wrap around effects).  
This usage makes me regret somewhat the switch.

>It can be worked around like this:
>
>  
>
Also.

where( a != -32766, a, a.max(rtype=int16))

Notice in this case you could also do

a[a==-32766] = a.max()

-Travis




More information about the SciPy-user mailing list