What is the numpy.real() function in NumPy?
Overview
The real() function in NumPy is used to return the real part of the complex argument that is passed to it.
Syntax
numpy.real(val)
Syntax for the "real()" function in NumPy
Parameter value
The real() function takes a single parameter value, val, which represents an input array that has complex values.
Return value
The real() function returns the real component of the val parameter value that is passed to it.
Example
import numpy as np# creating an input array of complex valuesx = np.array([1+2j, 2+3j, 1+5j])# implementing the real) functionmyarray = np.real(x)print(x)print(myarray)
Explanation
- Line 1: We import the
numpymodule. - Line 4: We create an array
xthat has complex values, using thearray()function. - Line 7: We implement the
real()function on the input array. We assign the result to a variable calledmyarray. - Line 9: We print the variable
x. - Line 10: We print the variable
myarray.