NUMPY BASIC EXERCISE 7


Create a program that tests whether the values of an array are not a number or NaN

The isnan() function is used for identifying the not a number values in Numpy.

Code

import numpy as np
arr = np.array([1, 0, 2, np.nan, 4, np.inf])
print("Initial array")
print(arr)
print("Checks the NaN values :")
print(np.isnan(arr))

Output

Initial array
[ 1.  0.  2. nan  4. inf]
Checks the NaN values :
[False False False  True False False]

Code Editor

import numpy as np arr = np.array([1, 0, 2, np.nan, 4, np.inf]) print("Initial array") print(arr) print("Checks the NaN values :") print(np.isnan(arr))