NumPy Tutorial NumPy Statistics NumPy References

NumPy - imag() function



The NumPy imag() function returns the imaginary part of the complex argument, element-wise. The syntax for using this function is given below:

Syntax

numpy.imag(val)

Parameters

val Required. Specify the input array (array_like).

Return Value

Returns imaginary component of the complex argument, element-wise.

Example:

The example below shows the usage of imag() function.

import numpy as np

Arr = np.array([[1+2j,2+4j],
                [3+6j,4+8j]])

print("Arr is:")
print(Arr)

#imaginary part of Arr
print("\nImaginary part of Arr is:")
print(np.imag(Arr))

The output of the above code will be:

Arr is:
[[1.+2.j 2.+4.j]
 [3.+6.j 4.+8.j]]

Imaginary part of Arr is:
[[2. 4.]
 [6. 8.]]

❮ NumPy - Functions