Python Practice › NumPy Programs › Program 5
Element-wise complex test
Write a NumPy program to test element-wise for complex numbers.
Input
[2, 4, 6+9j, 7]
Output
[False False True False]
Approach
np.iscomplex()is True where the imaginary part is non-zero.
Solution
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.