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

Stéfan van der Walt stefan at sun.ac.za
Sun Jan 25 08:03:22 EST 2009


2009/1/25 Matthew Brett <matthew.brett at 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