dpnp.allclose
- dpnp.allclose(a, b, rtol=1e-05, atol=1e-08, equal_nan=False)[source]
Returns
True
if 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 ifequal_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.allclose
.- 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. IfTrue
,NaNs
in a will be considered equal toNaNs
in b in the output array. Default:False
.
- Returns:
out -- A 0-dim array with
True
value if the two arrays are equal within the given tolerance; withFalse
otherwise.- Return type:
dpnp.ndarray
See also
dpnp.isclose
Test whether two arrays are element-wise equal.
dpnp.all
Test whether all elements evaluate to True.
dpnp.any
Test whether any element evaluates to True.
dpnp.equal
Return (x1 == x2) element-wise.
Notes
The comparison of a and b uses standard broadcasting, which means that a and b need not have the same shape in order for
dpnp.allclose(a, b)
to evaluate toTrue
. The same is true fordpnp.equal
but notdpnp.array_equal
.Examples
>>> import dpnp as np >>> a = np.array([1e10, 1e-7]) >>> b = np.array([1.00001e10, 1e-8]) >>> np.allclose(a, b) array(False)
>>> a = np.array([1.0, np.nan]) >>> b = np.array([1.0, np.nan]) >>> np.allclose(a, b) array(False) >>> np.allclose(a, b, equal_nan=True) array(True)
>>> a = np.array([1.0, np.inf]) >>> b = np.array([1.0, np.inf]) >>> np.allclose(a, b) array(True)