NUMPY BASIC EXERCISE 6
Create a program that tests whether the values of an array are infinite.
The sample program checks whether the values present inside the array are infinite or not by using the isinf() 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 infinity of the elements :") print(np.isinf(arr))
Output
Initial array [ 1. 0. 2. 3. 4. inf] Checks the infinity of the elements : [False False False False False True]
Code Editor
import numpy as np
arr = np.array([1, 0, 2, 3, 4, np.inf])
print("Initial array")
print(arr)
print("Checks the infinity of the elements :")
print(np.isinf(arr))