The imag()
function in NumPy returns the imaginary part of the complex argument passed to it.
numpy.imag(val)
The imag()
function takes a single parameter value (val
) that represents an input with complex values. This val
value can be a variable or an array.
The imag()
function returns the imaginary component of the input (val
) passed to it.
import numpy as np# creating a complex variable and an array of complex valuesmy_var = 1+4jmy_array = np.array([1+2j, 2+3j, 1+5j])# implementing the imag() functionimag_var = np.imag(my_var)imag_array = np.imag(my_array)print(my_var)print(imag_var)print(my_array)print(imag_array)
numpy
module.my_var
And an array, my_array
that contains complex values.imag()
function on the inputs. We assign the result of my_var
to a variable, imag_var
And the result of my_array
to imag_array
.my_var
, which contains the complex argument.imag_var
which only contains the imaginary value of my_var
.my_array
, which contains the complex values.imag_array
which only contains the imaginary values of my_array
.