A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://docs.scipy.org/doc/numpy/reference/generated/numpy.real_if_close.html below:

numpy.real_if_close — NumPy v2.3 Manual

numpy.real_if_close#
numpy.real_if_close(a, tol=100)[source]#

If input is complex with all imaginary parts close to zero, return real parts.

“Close to zero” is defined as tol * (machine epsilon of the type for a).

Parameters:
aarray_like

Input array.

tolfloat

Tolerance in machine epsilons for the complex part of the elements in the array. If the tolerance is <=1, then the absolute tolerance is used.

Returns:
outndarray

If a is real, the type of a is used for the output. If a 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

>>> import numpy as np
>>> np.finfo(float).eps
2.2204460492503131e-16 # may vary
>>> np.real_if_close([2.1 + 4e-14j, 5.2 + 3e-15j], tol=1000)
array([2.1, 5.2])
>>> np.real_if_close([2.1 + 4e-13j, 5.2 + 3e-15j], tol=1000)
array([2.1+4.e-13j, 5.2 + 3e-15j])

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4