4.20. Array Inf and NaN

4.20.1. Infinite

import numpy as np


np.inf
# inf
import numpy as np


np.inf + 1          # inf
np.inf + np.inf     # inf
np.inf - np.inf     # nan
np.inf - np.nan     # nan

np.inf * np.inf     # inf
np.inf / np.inf     # nan

0 / np.inf          # 0.0
np.inf / 0          # ZeroDivisionError: float division by zero
import numpy as np


a = np.array([1, 2, np.Inf])
# array([ 1.,  2., inf])

np.isfinite(a)
# array([ True,  True, False])

np.isinf(a)
# array([False, False,  True])
import numpy as np


a = np.array([1, 2, np.Inf])
# array([ 1.,  2., inf])

np.isnan(a)
# array([False, False, False])

4.20.2. Not-a-Number

  • Special float value

  • Propagates in calculations

import numpy as np


np.nan
# nan
import numpy as np


np.nan + 1          # nan
np.nan + np.nan     # nan
np.nan - np.nan     # nan
np.nan - np.inf     # nan

np.nan / np.nan     # nan
0 / np.nan          # nan
np.nan / 0          # ZeroDivisionError: float division by zero
import numpy as np


a = np.array([1, 2, np.NaN])
# array([ 1.,  2., nan])

np.isnan(a)
# array([False, False,  True])
import numpy as np


a = np.array([1, 2, np.NaN])
# array([ 1.,  2., nan])

np.isfinite(a)
# array([ True,  True, False])

np.isinf(a)
# array([False, False, False])

4.20.3. Assignments

Todo

Create Assignments