numpy.real_if_close
-
numpy.real_if_close(a, tol=100)
[source] -
If complex input returns a real array if complex parts are close to zero.
“Close to zero” is defined as
tol
* (machine epsilon of the type fora
).Parameters: -
a : array_like
-
Input array.
-
tol : float
-
Tolerance in machine epsilons for the complex part of the elements in the array.
Returns: -
out : ndarray
-
If
a
is real, the type ofa
is used for the output. Ifa
has complex elements, the returned type is float.
Notes
Machine epsilon varies from machine to machine and between data types but Python floats on most platforms have a machine epsilon equal to 2.2204460492503131e-16. You can use ‘np.finfo(float).eps’ to print out the machine epsilon for floats.
Examples
>>> np.finfo(float).eps 2.2204460492503131e-16
>>> np.real_if_close([2.1 + 4e-14j], tol=1000) array([ 2.1]) >>> np.real_if_close([2.1 + 4e-13j], tol=1000) array([ 2.1 +4.00000000e-13j])
-
© 2005–2019 NumPy Developers
Licensed under the 3-clause BSD License.
https://docs.scipy.org/doc/numpy-1.15.4/reference/generated/numpy.real_if_close.html