+
+ +
+

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.

  • +
  • tol (scalar, 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:
+

out -- If a is real, the type of a is used for the output. If a has +complex elements, the returned type is float.

+
+
Return type:
+

dpnp.ndarray

+
+
+
+

See also

+
+
dpnp.real

Return the real part of the complex argument.

+
+
dpnp.imag

Return the imaginary part of the complex argument.

+
+
dpnp.angle

Return 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])
+
+
+
+ +
+ + +
+