Python Practice › NumPy Programs › Program 3
Element-wise finite test
Write a NumPy program to test element-wise whether values are finite.
Input
[6, 8, 3, np.inf]
Output
[ True True True False]
Approach
np.isfinite().
Solution
import numpy as npprint(np.isfinite(np.array([6, 8, 3, np.inf])))Output
[ True True True False]
Note
The original sample output was inverted; isfinite is True for normal numbers and False for infinity.
Learn the concept
New to this topic? Read the lesson, then come back.