Write a NumPy program to test element-wise for complex number, real number of a given array. Also test whether a given number is a scalar type or not.
import numpy as np a = np.array([1+1j, 1+0j, 4.5, 3, 2, 2j]) print("Original array") print(a) print("Checking for complex number:") print(np.iscomplex(a)) print("Checking for real number:") print(np.isreal(a)) print("Checking for scalar type:") print(np.isscalar(3.1)) print(np.isscalar([3.1]))
Sample Output:
Original array [ 1.0+1.j 1.0+0.j 4.5+0.j 3.0+0.j 2.0+0.j 0.0+2.j] Checking for complex number: [ True False False False False True] Checking for real number: [False True True True True False] Checking for scalar type: True False
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Sample Output:
need an explanation for this answer? contact us directly to get an explanation for this answer