The real_if_close()
function in NumPy is used to return real parts of an input array of complex values with all imaginary parts close to zero.
np.real_if_close(a, tol=100)
The real_if_close()
function takes the following parameter values:
a
: This represents the input array. This is a required parameter.tol
: This represents the tolerance in machine epsilons for the complex part of the input array elements. This is a required parameter.Note: Machine epsilons represent the smallest positive float value greater than zero.
The real_if_close()
function returns a float if the input array has complex elements. If the input array is real, its data type is the same for the output.
import numpy as np# creating an input arrayx = np.array([10.4 + 10e-14j, 15.5 + 15e-15j])# defining the real_if_close() functionmyarray = np.real_if_close(x, tol=1000)print(myarray)
numpy
module.x
, using the array()
function.real_if_close()
function on the input array, x
. We assign the result to a variable myarray
.myarray
.