[Numpy-discussion] Floating point "close" function?
Sat Mar 3 17:33:49 CST 2012
On Sat, Mar 3, 2012 at 12:50 PM, Olivier Delalleau <firstname.lastname@example.org> wrote:
>> Would it be helpful if I went ahead and submitted a pull request with the
>> function in my original question called "isclose" (along with a complete
>> docstring and a few tests)?
>> One note:
>> At the moment, it deliberately compares NaN's as equal. E.g.
>> isclose([np.nan, np.nan], [np.nan, np.nan])
>> will return:
>> [True, True]
>> This obviously runs counter to the standard way NaN's are handled (and
>> indeed the definition of NaN).
>> However, in the context of a floating point "close to" function, I think
>> it makes the most sense.
>> I've had this sitting around in a small project for awhile now, and it's
>> been more useful to have it compare NaN's as "approximately equal" than not
>> for my purposes at least.
>> Nonetheless, it's something that needs additional consideration.
> It would be confusing if numpy.isclose().all() was different from
> numpy.allclose(). That being said, I agree it's useful to have NaNs compare
> equal in some cases, maybe it could be a new argument to the function?
Good point. I went ahead and added an "equal_nan" kwarg and removed the
"check_invalid" kwarg I had in before. I also made it mimic what
np.equal() does in the case of two scalars (return a scalar instead of an
I went ahead an make a pull request:
https://github.com/numpy/numpy/pull/224 Hope that's alright.
> -=- Olivier
> NumPy-Discussion mailing list
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the NumPy-Discussion