MCPcopy Index your code
hub / github.com/numpy/numpy / allclose

Function allclose

numpy/ma/core.py:8517–8623  ·  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

8515
8516
8517def allclose(a, b, masked_equal=True, rtol=1e-5, atol=1e-8):
8518 """
8519 Returns True if two arrays are element-wise equal within a tolerance.
8520
8521 This function is equivalent to `allclose` except that masked values
8522 are treated as equal (default) or unequal, depending on the `masked_equal`
8523 argument.
8524
8525 Parameters
8526 ----------
8527 a, b : array_like
8528 Input arrays to compare.
8529 masked_equal : bool, optional
8530 Whether masked values in `a` and `b` are considered equal (True) or not
8531 (False). They are considered equal by default.
8532 rtol : float, optional
8533 Relative tolerance. The relative difference is equal to ``rtol * b``.
8534 Default is 1e-5.
8535 atol : float, optional
8536 Absolute tolerance. The absolute difference is equal to `atol`.
8537 Default is 1e-8.
8538
8539 Returns
8540 -------
8541 y : bool
8542 Returns True if the two arrays are equal within the given
8543 tolerance, False otherwise. If either array contains NaN, then
8544 False is returned.
8545
8546 See Also
8547 --------
8548 all, any
8549 numpy.allclose : the non-masked `allclose`.
8550
8551 Notes
8552 -----
8553 If the following equation is element-wise True, then `allclose` returns
8554 True::
8555
8556 absolute(`a` - `b`) <= (`atol` + `rtol` * absolute(`b`))
8557
8558 Return True if all elements of `a` and `b` are equal subject to
8559 given tolerances.
8560
8561 Examples
8562 --------
8563 >>> import numpy as np
8564 >>> a = np.ma.array([1e10, 1e-7, 42.0], mask=[0, 0, 1])
8565 >>> a
8566 masked_array(data=[10000000000.0, 1e-07, --],
8567 mask=[False, False, True],
8568 fill_value=1e+20)
8569 >>> b = np.ma.array([1e10, 1e-8, -42.0], mask=[0, 0, 1])
8570 >>> np.ma.allclose(a, b)
8571 False
8572
8573 >>> a = np.ma.array([1e10, 1e-8, 42.0], mask=[0, 0, 1])
8574 >>> b = np.ma.array([1.00001e10, 1e-9, -42.0], mask=[0, 0, 1])

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.85
filledMethod · 0.45
allMethod · 0.45
anyMethod · 0.45

Tested by 5

eqFunction · 0.72
test_testAverage2Method · 0.72
test_allcloseMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…