Overview:
-
A complex number is the number of the form a+ib, where “a" is the real part and “b” is the imaginary part. Both “a” and “b” are real numbers.
-
Complex numbers have their applications from solving polynomials to describing wave forms, signal processing, fluid dynamics, quantum physics and other areas of science.
-
The NumPy function iscomplex() checks an element whether it is a complex number and the result is True if the imaginary part is non-zero. The results are returned as an array of Boolean values. When the input is scalar, the function returns a Boolean value.
Example:
In Python, a complex number can be directly constructed in two ways:
- By invoking the built-in function complex().
- By adding a complex number whose real part is zero(e.g., 1j, -2j, 5j) to a real or integer value e.g., 2+5j, 4-3j.
The NumPy example below constructs complex numbers using the second approach. e.g.,10+4j
# Example Python program that checks # Create an ndarray complex1 = 10+4j complex2 = 3+0j complex3 = 0+1j # Populate the ndarray with complex numbers # Check for complex numbers whose imaginary part is non-zero |
Output:
(10+4j) <class 'complex'> (3+0j) <class 'complex'> [[10.+4.j 3.+0.j] [ 0.+1.j 0.+0.j]] [[ True False] [ True False]] |