Element-wise finite test

EasyNumPy Programs · 3 of 100

Write a NumPy program to test element-wise whether values are finite.

Advertisement
Input
[6, 8, 3, np.inf]
Output
[ True  True  True False]

Approach

  1. np.isfinite().

Solution

Python
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.

More numpy programs

← All 100 NumPy Programs

Leave a Comment