numpy 1.22.4 Pypi GitHub Homepage
Other Docs
NotesParametersReturnsBackRef
real_if_close(a, tol=100)

"Close to zero" is defined as :None:None:`tol` * (machine epsilon of the type for a).

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.

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 of a is used for the output. If a has complex elements, the returned type is float.

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

See Also

angle
imag
real

Examples

>>> 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])
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

numpy.real numpy.imag

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


GitHub : /numpy/lib/type_check.py#529
type: <class 'function'>
Commit: