Element-wise complex test

EasyNumPy Programs · 5 of 100

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

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

Approach

  1. np.iscomplex() is True where the imaginary part is non-zero.

Solution

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

Learn the concept

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

More numpy programs

← All 100 NumPy Programs

Leave a Comment