Returns true if all components of a and b are equal to given tolerances. If fill_value is True, masked values considered equal. Otherwise, masked values are considered unequal. The relative error rtol should be positive and << 1.0 The absolute error atol comes into play for th
(a, b, fill_value=True, rtol=1e-5, atol=1e-8)
| 39 | |
| 40 | |
| 41 | def approx(a, b, fill_value=True, rtol=1e-5, atol=1e-8): |
| 42 | """ |
| 43 | Returns true if all components of a and b are equal to given tolerances. |
| 44 | |
| 45 | If fill_value is True, masked values considered equal. Otherwise, |
| 46 | masked values are considered unequal. The relative error rtol should |
| 47 | be positive and << 1.0 The absolute error atol comes into play for |
| 48 | those elements of b that are very small or zero; it says how small a |
| 49 | must be also. |
| 50 | |
| 51 | """ |
| 52 | m = mask_or(getmask(a), getmask(b)) |
| 53 | d1 = filled(a) |
| 54 | d2 = filled(b) |
| 55 | if d1.dtype.char == "O" or d2.dtype.char == "O": |
| 56 | return np.equal(d1, d2).ravel() |
| 57 | x = filled(masked_array(d1, copy=False, mask=m), fill_value).astype(float_) |
| 58 | y = filled(masked_array(d2, copy=False, mask=m), 1).astype(float_) |
| 59 | d = np.less_equal(umath.absolute(x - y), atol + rtol * umath.absolute(y)) |
| 60 | return d.ravel() |
| 61 | |
| 62 | |
| 63 | def almost(a, b, decimal=6, fill_value=True): |