[Numpy-discussion] detecting a nan with all() or any()

Robert Kern robert.kern@gmail....
Tue Oct 21 11:07:35 CDT 2008

On Tue, Oct 21, 2008 at 10:30, Vasileios Gkinis <v.gkinis@gfy.ku.dk> wrote:
> Hi,
> I would like to detect if my array for example a = array((1,2,3,nan))
> contains any nans
> So when i use:
> In [31]: all(a!=nan)
> I get
> Out[31]: True
> And when i use:
> In [35]: any(a==nan)
> I get
> Out[35]: False
> Which looks rather wrong to me...or i am simply missing something
> Can somebody comment on that...?

One of the properties of nans is that nan!=nan. Instead, use the
function isnan().

Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
  -- Umberto Eco

More information about the Numpy-discussion mailing list