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

Function allclose

numpy/core/numeric.py:2171–2242  ·  view source on GitHub ↗

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 b

(a, b, rtol=1.e-5, atol=1.e-8, equal_nan=False)

Source from the content-addressed store, hash-verified

2169
2170@array_function_dispatch(_allclose_dispatcher)
2171def allclose(a, b, rtol=1.e-5, atol=1.e-8, equal_nan=False):
2172 """
2173 Returns True if two arrays are element-wise equal within a tolerance.
2174
2175 The tolerance values are positive, typically very small numbers. The
2176 relative difference (`rtol` * abs(`b`)) and the absolute difference
2177 `atol` are added together to compare against the absolute difference
2178 between `a` and `b`.
2179
2180 NaNs are treated as equal if they are in the same place and if
2181 ``equal_nan=True``. Infs are treated as equal if they are in the same
2182 place and of the same sign in both arrays.
2183
2184 Parameters
2185 ----------
2186 a, b : array_like
2187 Input arrays to compare.
2188 rtol : float
2189 The relative tolerance parameter (see Notes).
2190 atol : float
2191 The absolute tolerance parameter (see Notes).
2192 equal_nan : bool
2193 Whether to compare NaN's as equal. If True, NaN's in `a` will be
2194 considered equal to NaN's in `b` in the output array.
2195
2196 .. versionadded:: 1.10.0
2197
2198 Returns
2199 -------
2200 allclose : bool
2201 Returns True if the two arrays are equal within the given
2202 tolerance; False otherwise.
2203
2204 See Also
2205 --------
2206 isclose, all, any, equal
2207
2208 Notes
2209 -----
2210 If the following equation is element-wise True, then allclose returns
2211 True.
2212
2213 absolute(`a` - `b`) <= (`atol` + `rtol` * absolute(`b`))
2214
2215 The above equation is not symmetric in `a` and `b`, so that
2216 ``allclose(a, b)`` might be different from ``allclose(b, a)`` in
2217 some rare cases.
2218
2219 The comparison of `a` and `b` uses standard broadcasting, which
2220 means that `a` and `b` need not have the same shape in order for
2221 ``allclose(a, b)`` to evaluate to True. The same is true for
2222 `equal` but not `array_equal`.
2223
2224 `allclose` is not defined for non-numeric data types.
2225 `bool` is considered a numeric data-type for this purpose.
2226
2227 Examples
2228 --------

Callers 1

test_roundtripMethod · 0.90

Calls 2

iscloseFunction · 0.85
allFunction · 0.70

Tested by 1

test_roundtripMethod · 0.72