3 ms·
Not mentioned in the article but numpy.isclose() works for 0.0 case unlike math.isclose().
by nabla9 5y ago
Not mentioned in the article but numpy.isclose() works for 0.0 case unlike math.isclose().
- da12 5y agoCould you explain what you mean the 0.0 case? math.isclose() has an abs_tol parameter for, among other things, handling comparisons to 0.
- macintux 5y agoI assume “out of the box” is the distinction.
- longemen3000 5y agoThe Julia equivalent does a good job explaining the 0.0 case: https://docs.julialang.org/en/v1/base/math/#Base.isapprox https://docs.julialang.org/en/v1/base/math/#Base.isapprox
- PennRobotics 5y agoAn explanation for the atol difference between numpy and math, by the author of math.isclose(): https://github.com/numpy/numpy/issues/10161#issuecomment-350021545 https://github.com/numpy/numpy/issues/10161#issuecomment-350... plus a ton of flogging/benchmarking common libraries (numpy, scipy, scikit-learn) and discussion about np.isclose() ... and also this gem: import numpy as np a = 1 b = 10 rtol = 1 atol = 0 np.isclose(a, b, rtol=rtol, atol=atol) # True np.isclose(b, a, rtol=rtol, atol=atol) # False (For the record:) import math math.isclose(a, b, rel_tol=rtol, abs_tol=atol) # True math.isclose(b, a, rel_tol=rtol, abs_tol=atol) # True