dpnp.allclose
- dpnp.allclose(a, b, rtol=1e-05, atol=1e-08, equal_nan=False)[source]
Returns
Trueif 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.
NaNsare treated as equal if they are in the same place and ifequal_nan=True.Infsare 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
NaNsas equal. IfTrue,NaNsin a will be considered equal toNaNsin b in the output array.Default:
False.
- Returns:
out -- A 0-d array with
Truevalue if the two arrays are equal within the given tolerance; withFalseotherwise.- Return type:
dpnp.ndarray of bool dtype
See also
dpnp.iscloseTest whether two arrays are element-wise equal.
dpnp.allTest whether all elements evaluate to True.
dpnp.anyTest whether any element evaluates to True.
dpnp.equalReturn (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.equalbut 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)