[SciPy-User] putmask and NaNs

josef.pktd@gmai... josef.pktd@gmai...
Thu Feb 25 11:38:42 CST 2010

On Thu, Feb 25, 2010 at 12:26 PM, kpal <kpalamartchouk@gmail.com> 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])
> At this moment I expect some of the values in mydata to be replaced by
> NaNs, but they get replaced by zeros. Is this behaviour normal? Or is
> it a bug?
> Or is there another way to put NaNs according to a mask?

It's not a problem with putmask

integer arrays cannot contain nans so they are silently cast to zero.

If you need nans than either use a float array or represent nans as
-9999 or something like this, or use masked arrays.


> Python 2.5, scipy 0.7.0
> Thanks,
> _______________________________________________
> SciPy-User mailing list
> SciPy-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user

More information about the SciPy-User mailing list