[Numpy-discussion] How do I test if an array contains NaN ?

Fernando Perez fperez.net at gmail.com
Thu Jan 4 17:25:09 CST 2007


On 1/4/07, Robert Kern <robert.kern at gmail.com> wrote:
> Sebastian Haase wrote:
> > Hi!
> >
> > Simple question:
> > How do I test if an array contains NaN ?
> > Or others like inf ...?
>
> In [1633]: isinf?
> Type:           ufunc
> Base Class:     <type 'numpy.ufunc'>
> Namespace:      Interactive
> Docstring:
>     y = isinf(x) returns True where x is +inf or -inf

[...]

It's probably worth mentioning that IPython has (thanks to a user
contributed implementation) search capabilities besides tab completion
(which requires you to at least know the start of the string you
want):

In [3]: N.*nan*?
N.isnan
N.nan
N.nan_to_num
N.nanargmax
N.nanargmin
N.nanmax
N.nanmin
N.nansum

In [4]: N.*inf*?
N.finfo
N.inf
N.info
N.infty
N.isinf
N.isneginf
N.isposinf


This can be very useful when querying a package for something you only
vaguely know how it might be called.  This just prints the list of
names to stdout, you then need to actually type the one you want.

Cheers,

f


More information about the Numpy-discussion mailing list