Function signature:
iscomplexobj(object)
Parameters:
object – A Python object. A NumPy scalar or any Python container including a Numpy array.
Return value:
Returns True when the parameter passed is a complex type. Also returns True when a container passed in has at least one element as complex type.
Overview:
-
The NumPy function iscomplexobj() checks whether the parameter passed is a complex number. When the parameter is an ndarray or any other Python container the function iscomplexobj() checks whether the container has at least one element of complex type.
-
The behaviour of the NumPy function iscomplexobj() is different from the NumPy function iscomplex().The function iscomplexobj() returns True when the imaginary part of the complex number is zero. The isComplex() function returns True only when the imaginary part of the complex number is non-zero. The function iscomplexobj() returns True when one of the elements in a container(e.g. list, tuple) is a complex number. The function iscomplex() checks each element of an ndarray whether it is a complex number and returns the result as an ndarray of Boolean values.
Example 1:
# Example Python program that uses iscomplexobj() function c1 = 3+4j # Imaginary part is zero # Use the built-in function complex # Use the numpy complex type |
Output:
True True <class 'complex'> True <class 'numpy.complex128'> True |
Example 2:
The example uses a list, tuple and ndarray with a complex number as one of their elements and the function iscomplexobj() returns True when these instances are passed as arguments. The function iscomplexobj() returns False when the container is a set or a dict.
# Example Python program that checks whether # Working with a list # Working with a tuple # The semantics of returning True when at-least one of the elements # Working with a NumPy array retVal = numpy.iscomplexobj(container4) |
Output:
True True False True |