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

Function almost

numpy/ma/testutils.py:63–79  ·  view source on GitHub ↗

Returns True if a and b are equal up to decimal places. If fill_value is True, masked values considered equal. Otherwise, masked values are considered unequal.

(a, b, decimal=6, fill_value=True)

Source from the content-addressed store, hash-verified

61
62
63def almost(a, b, decimal=6, fill_value=True):
64 """
65 Returns True if a and b are equal up to decimal places.
66
67 If fill_value is True, masked values considered equal. Otherwise,
68 masked values are considered unequal.
69
70 """
71 m = mask_or(getmask(a), getmask(b))
72 d1 = filled(a)
73 d2 = filled(b)
74 if d1.dtype.char == "O" or d2.dtype.char == "O":
75 return np.equal(d1, d2).ravel()
76 x = filled(masked_array(d1, copy=False, mask=m), fill_value).astype(float_)
77 y = filled(masked_array(d2, copy=False, mask=m), 1).astype(float_)
78 d = np.around(np.abs(x - y), decimal) <= 10.0 ** (-decimal)
79 return d.ravel()
80
81
82def _assert_equal_on_sequences(actual, desired, err_msg=''):

Callers 1

compareFunction · 0.85

Calls 5

mask_orFunction · 0.85
getmaskFunction · 0.85
filledFunction · 0.85
astypeMethod · 0.80
ravelMethod · 0.45

Tested by

no test coverage detected