---
jupyter:
  orphan: true
  jupytext:
    notebook_metadata_filter: all,-language_info
    split_at_heading: true
    text_representation:
      extension: .Rmd
      format_name: rmarkdown
      format_version: '1.2'
      jupytext_version: 1.13.7
  kernelspec:
    display_name: Python 3
    language: python
    name: python3
---

# Not a number

[Not a number](https://en.wikipedia.org/wiki/NaN) is a special floating point
value to signal that the result of a floating point calculation is invalid.

In text we usually use NaN to refer to the Not-a-Number value.

For example, dividing 0 by 0 is invalid, and returns a NaN value:

```{python}
import numpy as np
```

```{python}
np.array(0) / 0
```

As you see above, Numpy uses all lower-case: `nan` for the NaN value.

You can also find the NaN value in the Numpy module:

```{python}
np.nan
```


## NaN values are not equal to anything


The NaN value has some specific properties.

It is not equal to anything, even itself:

```{python}
np.nan == 0
```

```{python}
np.nan == np.nan
```

## Detecting NaN values

You have found above that you cannot look for NaN values by using `== np.nan`.

To allow for this, use `np.isnan` to tell you whether a number or an array
element is NaN.

```{python}
np.isnan([0, np.nan])
```
