bundles / numpy 2.4.3 / numpy / ma / core / allclose
function
numpy.ma.core:allclose
source: /numpy/ma/core.py :8446
Signature
def allclose ( a , b , masked_equal = True , rtol = 1e-05 , atol = 1e-08 ) Summary
Returns True if two arrays are element-wise equal within a tolerance.
Extended Summary
This function is equivalent to allclose except that masked values are treated as equal (default) or unequal, depending on the masked_equal argument.
Parameters
a, b: array_likeInput arrays to compare.
masked_equal: bool, optionalWhether masked values in
aandbare considered equal (True) or not (False). They are considered equal by default.rtol: float, optionalRelative tolerance. The relative difference is equal to
rtol * b. Default is 1e-5.atol: float, optionalAbsolute tolerance. The absolute difference is equal to
atol. Default is 1e-8.
Returns
y: boolReturns True if the two arrays are equal within the given tolerance, False otherwise. If either array contains NaN, then False is returned.
Notes
If the following equation is element-wise True, then allclose returns True
absolute(`a` - `b`) <= (`atol` + `rtol` * absolute(`b`))Return True if all elements of a and b are equal subject to given tolerances.
Examples
import numpy as np a = np.ma.array([1e10, 1e-7, 42.0], mask=[0, 0, 1]) a b = np.ma.array([1e10, 1e-8, -42.0], mask=[0, 0, 1]) np.ma.allclose(a, b)
a = np.ma.array([1e10, 1e-8, 42.0], mask=[0, 0, 1]) b = np.ma.array([1.00001e10, 1e-9, -42.0], mask=[0, 0, 1]) np.ma.allclose(a, b) np.ma.allclose(a, b, masked_equal=False)Masked values are not compared directly.
a = np.ma.array([1e10, 1e-8, 42.0], mask=[0, 0, 1]) b = np.ma.array([1.00001e10, 1e-9, 42.0], mask=[0, 0, 1]) np.ma.allclose(a, b) np.ma.allclose(a, b, masked_equal=False)
See also
- all
- any
- numpy.allclose
the non-masked
allclose.
Aliases
-
numpy.ma.allclose