# [SciPy-user] nan?

Joshua Petterson joshuafr at gmail.com
Thu Nov 30 02:55:08 CST 2006

```Hi Robert,
thanks for these precisions. I don't want to start a troll in this
m-l, but why numpy doesn't understand nan and masked_values together?
And a mix of them doen't work:
Out [40]:array(nan)
Out [41]:array(nan)

Then, if I have missing values in my datas, what can I do? I cannot
compute on nan, and numpy.ma doesn't recognize it. I could use isnan
to find them, but what's that?:
|~|[48]>a=[1,2,nan]
|~|[50]>b
Out [50]:
array(data =
[  1.00000000e+00   2.00000000e+00   1.00000000e+20],
[False False True],
fill_value=1e+20)

nan becomes 1e+20!!! Good precision :-)

2006/11/30, Robert Kern <robert.kern at gmail.com>:
> Joshua Petterson wrote:
> > hello,
> > my question is maybe trivial, but what is the utility of numpy.NAN?
>
> It's a special kind of floating point number defined by the IEEE-754 floating
> point specification. It means that it is "Not a Number". It comes out of certain
> floating point operations (e.g. inf/inf) to specify that the operation actually
> has indeterminate value or that the operation is invalid.
>
> The alternative is to raise an exception every time such an operation occurs.
> With arrays, that kind of behavior is often undesirable since it means that all
> of your expensive calculations stop even though only one element was bad.
> Returning NaNs for those values might allow the programmer to inspect the
> results and locate the problem (if indeed it is a problem). Of course, sometimes
> you want an exception to be raised to stop execution. You can control this
> behavior with numpy.seterr().
>
> One of the quirks of NaNs is that they are defined to not equal anything,
> including themselves. You can use numpy.isnan() to locate NaNs. In some systems,
> NaNs are used as a way to represent missing data (people often have strong
> opinions about this, both for and against; I'd advise searching the archives of
> this list for discussions about masked arrays instead of opening that argument
> again).
>
> You can find more information about NaNs and other tricky bits of floating point
> from the classic paper "What Every Computer Scientist Should Know About
> Floating-Point Arithmetic":
>
>   http://docs-pdf.sun.com/800-7895/800-7895.pdf
>
> --
> 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
> _______________________________________________
> SciPy-user mailing list
> SciPy-user at scipy.org
> http://projects.scipy.org/mailman/listinfo/scipy-user
>
```