NumPy ndarray.imag() Method | Get Imaginary Part in NumPy Array
Last Updated :
05 Feb, 2024
The ndarray.imag() method returns the imaginary part of the complex number in the NumPy array.
Note: Remember resulting data type for the imaginary value is ‘float64’.
Example
Python3
import numpy as np
gfg = np.array([ 1 + 2j , 2 + 3j ])
geeks = np.imag(gfg)
print (geeks, end = '\n\n' )
print (np.imag(geeks).dtype)
|
Syntax
Syntax: ndarray.imag()
Return
- Array of imaginary values having dtype ‘float64’
How to Find Imaginary Values of Complex Number in NumPy Array
To find the imaginary values in the NumPy array we use ndarray.imag() function of the NumPy library in Python.
Let us understand it better with an example:
Example: Find Imaginary Values in NumPy Array
Python3
import numpy as np
gfg = np.array([ 1 + 2j , 2 + 3j ])
gfg = np.sqrt(gfg)
geeks = np.imag(gfg)
print (geeks, end = '\n\n' )
print (np.imag(geeks).dtype)
|
Output
[ 0.78615138 0.89597748]
float64
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...