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

Function isclose

numpy/core/numeric.py:2250–2371  ·  view source on GitHub ↗

Returns a boolean array where 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 absolut

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

Source from the content-addressed store, hash-verified

2248
2249@array_function_dispatch(_isclose_dispatcher)
2250def isclose(a, b, rtol=1.e-5, atol=1.e-8, equal_nan=False):
2251 """
2252 Returns a boolean array where two arrays are element-wise equal within a
2253 tolerance.
2254
2255 The tolerance values are positive, typically very small numbers. The
2256 relative difference (`rtol` * abs(`b`)) and the absolute difference
2257 `atol` are added together to compare against the absolute difference
2258 between `a` and `b`.
2259
2260 .. warning:: The default `atol` is not appropriate for comparing numbers
2261 that are much smaller than one (see Notes).
2262
2263 Parameters
2264 ----------
2265 a, b : array_like
2266 Input arrays to compare.
2267 rtol : float
2268 The relative tolerance parameter (see Notes).
2269 atol : float
2270 The absolute tolerance parameter (see Notes).
2271 equal_nan : bool
2272 Whether to compare NaN's as equal. If True, NaN's in `a` will be
2273 considered equal to NaN's in `b` in the output array.
2274
2275 Returns
2276 -------
2277 y : array_like
2278 Returns a boolean array of where `a` and `b` are equal within the
2279 given tolerance. If both `a` and `b` are scalars, returns a single
2280 boolean value.
2281
2282 See Also
2283 --------
2284 allclose
2285 math.isclose
2286
2287 Notes
2288 -----
2289 .. versionadded:: 1.7.0
2290
2291 For finite values, isclose uses the following equation to test whether
2292 two floating point values are equivalent.
2293
2294 absolute(`a` - `b`) <= (`atol` + `rtol` * absolute(`b`))
2295
2296 Unlike the built-in `math.isclose`, the above equation is not symmetric
2297 in `a` and `b` -- it assumes `b` is the reference value -- so that
2298 `isclose(a, b)` might be different from `isclose(b, a)`. Furthermore,
2299 the default value of atol is not zero, and is used to determine what
2300 small values should be considered close to zero. The default value is
2301 appropriate for expected values of order unity: if the expected values
2302 are significantly smaller than one, it can result in false positives.
2303 `atol` should be carefully selected for the use case at hand. A zero value
2304 for `atol` will result in `False` if either `a` or `b` is zero.
2305
2306 `isclose` is not defined for non-numeric data types.
2307 `bool` is considered a numeric data-type for this purpose.

Callers 1

allcloseFunction · 0.85

Calls 7

asanyarrayFunction · 0.85
isfiniteFunction · 0.85
within_tolFunction · 0.85
isnanFunction · 0.85
allFunction · 0.70
zeros_likeFunction · 0.70
ones_likeFunction · 0.70

Tested by

no test coverage detected