Q:

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

0

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.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now