[SciPy-user] NaN's in numpy (and Scipy)

A. M. Archibald peridot.faceted at gmail.com
Sat Jan 6 17:28:42 EST 2007


On 06/01/07, Vincent Nijs <v-nijs at kellogg.northwestern.edu> wrote:
> It may be relevant to note that 'isnan' only seems to work with floats. If
> you change Pierre's example a bit, mask creation doesn't work as I might
> expect. If you create the array as follows
>
> >>> x = N.array([1,2,N.nan,4],dtype='int16')

[...]

> It might be convenient if an array would be automatically up-cast to float
> is an nan is present.

This is in fact the normal behaviour of numpy: if there's a
floating-point number in the array when you create it, the array gets
upcast - unless you specify the data type, forcing it to a particular
type. Which you did.

The unavailablity of NaNs for integer types is sometimes unfortunate,
but there's really nothing numpy can do about it.

A. M. Archibald



More information about the SciPy-User mailing list