Open In App

NumPy ndarray.imag() Method | Get Imaginary Part in NumPy Array

Last Updated : 05 Feb, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

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 the important module in python
import numpy as np
          
# make an array with numpy
gfg = np.array([1 + 2j, 2 + 3j])
          
# applying ndarray.imag() method
geeks = np.imag(gfg)
    
print(geeks, end ='\n\n')
print(np.imag(geeks).dtype)


Output

[ 2.  3.]

float64

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 the important module in python
import numpy as np
          
# make an array with numpy
gfg = np.array([1 + 2j, 2 + 3j])
gfg = np.sqrt(gfg)
          
# applying ndarray.imag() method
geeks = np.imag(gfg)
    
print(geeks, end ='\n\n')
print(np.imag(geeks).dtype)


Output

[ 0.78615138  0.89597748]

float64


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads