MCPcopy Create free account
hub / github.com/numpy/numpy / allclose

Function allclose

numpy/ma/core.py:8096–8201  ·  view source on GitHub ↗

Returns True if two arrays are element-wise equal within a tolerance. 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_like

(a, b, masked_equal=True, rtol=1e-5, atol=1e-8)

Source from the content-addressed store, hash-verified

8094
8095
8096def allclose(a, b, masked_equal=True, rtol=1e-5, atol=1e-8):
8097 """
8098 Returns True if two arrays are element-wise equal within a tolerance.
8099
8100 This function is equivalent to `allclose` except that masked values
8101 are treated as equal (default) or unequal, depending on the `masked_equal`
8102 argument.
8103
8104 Parameters
8105 ----------
8106 a, b : array_like
8107 Input arrays to compare.
8108 masked_equal : bool, optional
8109 Whether masked values in `a` and `b` are considered equal (True) or not
8110 (False). They are considered equal by default.
8111 rtol : float, optional
8112 Relative tolerance. The relative difference is equal to ``rtol * b``.
8113 Default is 1e-5.
8114 atol : float, optional
8115 Absolute tolerance. The absolute difference is equal to `atol`.
8116 Default is 1e-8.
8117
8118 Returns
8119 -------
8120 y : bool
8121 Returns True if the two arrays are equal within the given
8122 tolerance, False otherwise. If either array contains NaN, then
8123 False is returned.
8124
8125 See Also
8126 --------
8127 all, any
8128 numpy.allclose : the non-masked `allclose`.
8129
8130 Notes
8131 -----
8132 If the following equation is element-wise True, then `allclose` returns
8133 True::
8134
8135 absolute(`a` - `b`) <= (`atol` + `rtol` * absolute(`b`))
8136
8137 Return True if all elements of `a` and `b` are equal subject to
8138 given tolerances.
8139
8140 Examples
8141 --------
8142 >>> a = np.ma.array([1e10, 1e-7, 42.0], mask=[0, 0, 1])
8143 >>> a
8144 masked_array(data=[10000000000.0, 1e-07, --],
8145 mask=[False, False, True],
8146 fill_value=1e+20)
8147 >>> b = np.ma.array([1e10, 1e-8, -42.0], mask=[0, 0, 1])
8148 >>> np.ma.allclose(a, b)
8149 False
8150
8151 >>> a = np.ma.array([1e10, 1e-8, 42.0], mask=[0, 0, 1])
8152 >>> b = np.ma.array([1.00001e10, 1e-9, -42.0], mask=[0, 0, 1])
8153 >>> np.ma.allclose(a, b)

Callers 5

eqFunction · 0.90
test_testAverage2Method · 0.90
test_allcloseMethod · 0.90

Calls 7

mask_orFunction · 0.85
getmaskFunction · 0.85
filledFunction · 0.85
less_equalFunction · 0.50
filledMethod · 0.45
allMethod · 0.45
anyMethod · 0.45

Tested by 5

eqFunction · 0.72
test_testAverage2Method · 0.72
test_allcloseMethod · 0.72