[SciPy-user] scipy_core bug in where

Ted Horst ted.horst at earthlink.net
Thu Nov 17 10:32:35 CST 2005


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.

It can be worked around like this:

 >>> where(a != -32766, a, a.max().astype(int16))
array([1, 2, 3, 6, 4, 5, 6, 6], dtype=int16)



More information about the SciPy-user mailing list