[Numpy-discussion] Suggested change for NaN, Infs float->int conversion

Stéfan van der Walt stefan@sun.ac...
Sun Jan 25 07:03:22 CST 2009


2009/1/25 Matthew Brett <matthew.brett@gmail.com>:
> When converting arrays from float to ints, I notice that NaNs, Infs,
> and -Infs all get the minimum integer value:
>
>>>> flts = np.array([np.nan, np.inf, -np.inf])
>>>> flts.astype(np.int16)
> array([-32768, -32768, -32768], dtype=int16)
>
> However, setting NaNs into integer arrays gives a value of 0

I find this behaviour surprising too.  There is a ticket at

http://projects.scipy.org/scipy/numpy/ticket/980

Cheers
Stéfan


More information about the Numpy-discussion mailing list