dpnp.real_if_close¶
- dpnp.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).
For full documentation refer to
numpy.real_if_close.- Parameters:
- a{dpnp.ndarray, usm_ndarray}
Input array.
- tolscalar, optional
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.
Default:
100.
- Returns:
- outdpnp.ndarray
If a is real, the type of a is used for the output. If a has complex elements, the returned type is float.
See also
dpnp.realReturn the real part of the complex argument.
dpnp.imagReturn the imaginary part of the complex argument.
dpnp.angleReturn the angle of the complex argument.
Examples
>>> import dpnp as np >>> np.finfo(np.float64).eps 2.220446049250313e-16 # may vary
>>> a = np.array([2.1 + 4e-14j, 5.2 + 3e-15j]) >>> np.real_if_close(a, tol=1000) array([2.1, 5.2])
>>> a = np.array([2.1 + 4e-13j, 5.2 + 3e-15j]) >>> np.real_if_close(a, tol=1000) array([2.1+4.e-13j, 5.2+3.e-15j])