[SciPy-User] putmask and NaNs

Pierre GM pgmdevlist@gmail....
Thu Feb 25 11:40:24 CST 2010

On Feb 25, 2010, at 12:26 PM, kpal wrote:
> Hi, I observe a strange thing. scipy.putmask seems to treat NaN as
> zero in the following piece of code:
> mydata = scipy.array(((1,2,3,4,5),(1,1,-1,1,-1))).T
> scipy.putmask(mydata[:,0], mydata[:,1]<0, [scipy.NaN])

Let me guess, ``mydata`` has an integer dtype, right ? You can't use NaNs in that case, they are transformed into 0, as you've observed. That's a Python thing on versions lower than 2.6 (in 2.6, you get an exception).
You can:
* use masked arrays with your integer array, or
* transform your integer array into floats with .astype(float)

More information about the SciPy-User mailing list