diff options
author | chebee7i <chebee7i@gmail.com> | 2015-02-20 21:32:42 -0600 |
---|---|---|
committer | chebee7i <chebee7i@gmail.com> | 2015-02-20 21:41:44 -0600 |
commit | e1d3a0c66d719fe908de317c08b1234b71af196f (patch) | |
tree | b049785e40e8b12c757220a10992d237684b472c /numpy/core/numeric.py | |
parent | 2ae0529a5935c0eff0f72bb9f86d063537be250a (diff) | |
download | numpy-e1d3a0c66d719fe908de317c08b1234b71af196f.tar.gz |
ENH: Add `equal_nan` argument to allclose.
Diffstat (limited to 'numpy/core/numeric.py')
-rw-r--r-- | numpy/core/numeric.py | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/numpy/core/numeric.py b/numpy/core/numeric.py index 1519abcd4..1dba8af6a 100644 --- a/numpy/core/numeric.py +++ b/numpy/core/numeric.py @@ -2206,7 +2206,7 @@ def identity(n, dtype=None): from numpy import eye return eye(n, dtype=dtype) -def allclose(a, b, rtol=1.e-5, atol=1.e-8): +def allclose(a, b, rtol=1.e-5, atol=1.e-8, equal_nan=False): """ Returns True if two arrays are element-wise equal within a tolerance. @@ -2227,6 +2227,9 @@ def allclose(a, b, rtol=1.e-5, atol=1.e-8): The relative tolerance parameter (see Notes). atol : float The absolute tolerance parameter (see Notes). + equal_nan : bool + Whether to compare NaN's as equal. If True, NaN's in `a` will be + considered equal to NaN's in `b` in the output array. Returns ------- @@ -2259,9 +2262,11 @@ def allclose(a, b, rtol=1.e-5, atol=1.e-8): False >>> np.allclose([1.0, np.nan], [1.0, np.nan]) False + >>> np.allclose([1.0, np.nan], [1.0, np.nan], equal_nan=True) + True """ - return all(isclose(a, b, rtol=rtol, atol=atol)) + return all(isclose(a, b, rtol=rtol, atol=atol, equal_nan=equal_nan)) def isclose(a, b, rtol=1.e-5, atol=1.e-8, equal_nan=False): """ |