Element-wise real test

EasyNumPy Programs · 6 of 100

Write a NumPy program to test element-wise for real numbers.

Advertisement
Input
[2, 4, 6+9j, 7]
Output
[ True  True False  True]

Approach

  1. np.isreal().

Solution

Python
import numpy as npprint(np.isreal(np.array([2, 4, 6 + 9j, 7])))
Output
[ True  True False  True]
Advertisement

Learn the concept

New to this topic? Read the lesson, then come back.

More numpy programs

← All 100 NumPy Programs