Python | Numpy ndarray.real ()

With the Numpy ndarray.real () method, we can find real values ​​in imaginary expressions simply by using ndarray.real () . Remember that the resulting data type for the real value —  "float64" .

Syntax: ndarray.real()

Return: Array of Real values ​​having dtype 'float64'

Example # 1:
In this example, we can see that we are getting an array of real values ​​using ndarray.real () and we are also trying to print the dtype of those real values.

# import important module in python

import numpy as np

 
# make an array with NumPy

gfg = np.array ([ 1 + 2j 2 + 3j ])

 
# applying the ndarray.real () method

geeks = np.real (gfg)

 

print (geeks, end = '' )

print (np.real (geeks) .dtype)

Exit:

 [1. 2.] 'float64' 

Example # 2:

# import important module into python

import < / code> numpy as np

 
# make an array with NumPy

gfg = np.array ([ 1 + 2j , 2 + 3j ])

gfg = np.sqrt (gfg)

 
# applying the method ndarray.real ()

geeks = np.real (gfg)

 

print (geeks, end = '' )

print (np.real (geeks) .dtype)

Output:

 [1.27201965 1.67414923] float64 




Get Solution for free from DataCamp guru