NUMPY BASIC EXERCISE 5


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

The sample program checks whether the values present inside the array are finite or not by using the isfinite() function which will return a boolean value:

Code

import numpy as np
arr = np.array([1, 0, 2, 3, 4, np.inf])
print("Initial array")
print(arr)
print("Checks the finiteness of the elements :")
print(np.isfinite(arr))

Output

Initial array
[ 1.  0.  2.  3.  4. inf]
Checks the finiteness of the elements :
[ True  True  True  True  True False]

Code Editor

import numpy as np arr = np.array([1, 0, 2, 3, 4, np.inf]) print("Initial array") print(arr) print("Checks the finiteness of the elements :") print(np.isfinite(arr))