-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathnans.Rmd
68 lines (48 loc) · 1.25 KB
/
nans.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
---
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])
```