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)
| 2318 | |
| 2319 | @array_function_dispatch(_isclose_dispatcher) |
| 2320 | def isclose(a, b, rtol=1.e-5, atol=1.e-8, equal_nan=False): |
| 2321 | """ |
| 2322 | Returns a boolean array where two arrays are element-wise equal within a |
| 2323 | tolerance. |
| 2324 | |
| 2325 | The tolerance values are positive, typically very small numbers. The |
| 2326 | relative difference (`rtol` * abs(`b`)) and the absolute difference |
| 2327 | `atol` are added together to compare against the absolute difference |
| 2328 | between `a` and `b`. |
| 2329 | |
| 2330 | .. warning:: The default `atol` is not appropriate for comparing numbers |
| 2331 | with magnitudes much smaller than one (see Notes). |
| 2332 | |
| 2333 | Parameters |
| 2334 | ---------- |
| 2335 | a, b : array_like |
| 2336 | Input arrays to compare. |
| 2337 | rtol : array_like |
| 2338 | The relative tolerance parameter (see Notes). |
| 2339 | atol : array_like |
| 2340 | The absolute tolerance parameter (see Notes). |
| 2341 | equal_nan : bool |
| 2342 | Whether to compare NaN's as equal. If True, NaN's in `a` will be |
| 2343 | considered equal to NaN's in `b` in the output array. |
| 2344 | |
| 2345 | Returns |
| 2346 | ------- |
| 2347 | y : array_like |
| 2348 | Returns a boolean array of where `a` and `b` are equal within the |
| 2349 | given tolerance. If both `a` and `b` are scalars, returns a single |
| 2350 | boolean value. |
| 2351 | |
| 2352 | See Also |
| 2353 | -------- |
| 2354 | allclose |
| 2355 | math.isclose |
| 2356 | |
| 2357 | Notes |
| 2358 | ----- |
| 2359 | For finite values, isclose uses the following equation to test whether |
| 2360 | two floating point values are equivalent.:: |
| 2361 | |
| 2362 | absolute(a - b) <= (atol + rtol * absolute(b)) |
| 2363 | |
| 2364 | Unlike the built-in `math.isclose`, the above equation is not symmetric |
| 2365 | in `a` and `b` -- it assumes `b` is the reference value -- so that |
| 2366 | `isclose(a, b)` might be different from `isclose(b, a)`. |
| 2367 | |
| 2368 | The default value of `atol` is not appropriate when the reference value |
| 2369 | `b` has magnitude smaller than one. For example, it is unlikely that |
| 2370 | ``a = 1e-9`` and ``b = 2e-9`` should be considered "close", yet |
| 2371 | ``isclose(1e-9, 2e-9)`` is ``True`` with default settings. Be sure |
| 2372 | to select `atol` for the use case at hand, especially for defining the |
| 2373 | threshold below which a non-zero value in `a` will be considered "close" |
| 2374 | to a very small or zero value in `b`. |
| 2375 | |
| 2376 | `isclose` is not defined for non-numeric data types. |
| 2377 | :class:`bool` is considered a numeric data-type for this purpose. |
no test coverage detected
searching dependent graphs…