dpnp.isclose

dpnp.isclose(a, b, rtol=1e-05, atol=1e-08, equal_nan=False)[source]

Returns a boolean array where two arrays are element-wise equal within a tolerance.

The tolerance values are positive, typically very small numbers. The relative difference (rtol * abs(b)) and the absolute difference atol are added together to compare against the absolute difference between a and b.

NaNs are treated as equal if they are in the same place and if equal_nan=True. Infs are treated as equal if they are in the same place and of the same sign in both arrays.

For full documentation refer to numpy.isclose.

Parameters:
  • a ({dpnp.ndarray, usm_ndarray, scalar}) -- First input array, expected to have numeric data type. Both inputs a and b can not be scalars at the same time.

  • b ({dpnp.ndarray, usm_ndarray, scalar}) -- Second input array, also expected to have numeric data type. Both inputs a and b can not be scalars at the same time.

  • rtol ({dpnp.ndarray, usm_ndarray, scalar}, optional) -- The relative tolerance parameter. Default: 1e-05.

  • atol ({dpnp.ndarray, usm_ndarray, scalar}, optional) -- The absolute tolerance parameter. Default: 1e-08.

  • equal_nan (bool) -- Whether to compare NaNs as equal. If True, NaNs in a will be considered equal to NaNs in b in the output array. Default: False.

Returns:

out -- Returns a boolean array of where a and b are equal within the given tolerance.

Return type:

dpnp.ndarray

See also

dpnp.allclose

Returns True if two arrays are element-wise equal within a tolerance.

Examples

>>> import dpnp as np
>>> a = np.array([1e10, 1e-7])
>>> b = np.array([1.00001e10, 1e-8])
>>> np.isclose(a, b)
array([ True, False])
>>> a = np.array([1e10, 1e-8])
>>> b = np.array([1.00001e10, 1e-9])
>>> np.isclose(a, b)
array([ True,  True])
>>> a = np.array([1e10, 1e-8])
>>> b = np.array([1.0001e10, 1e-9])
>>> np.isclose(a, b)
array([False,  True])
>>> a = np.array([1.0, np.nan])
>>> b = np.array([1.0, np.nan])
>>> np.isclose(a, b)
array([ True, False])
>>> np.isclose(a, b, equal_nan=True)
array([ True,  True])
>>> a = np.array([0.0, 0.0])
>>> b = np.array([1e-8, 1e-7])
>>> np.isclose(a, b)
array([ True, False])
>>> b = np.array([1e-100, 1e-7])
>>> np.isclose(a, b, atol=0.0)
array([False, False])
>>> a = np.array([1e-10, 1e-10])
>>> b = np.array([1e-20, 0.0])
>>> np.isclose(a, b)
array([ True,  True])
>>> b = np.array([1e-20, 0.999999e-10])
>>> np.isclose(a, b, atol=0.0)
array([False,  True])