isclose() computes the exact same tolerance-based comparison as allclose() for each corresponding pair of elements, but returns the full per-element boolean array instead of reducing it down to one combined result — which lets you see exactly which elements matched and which didn't, rather than only knowing whether all of them did. np.allclose(a, b) is functionally equivalent to applying np.all() to the result of np.isclose(a, b).
1Understanding np.isclose()
isclose() computes the exact same tolerance-based comparison as allclose() for each corresponding pair of elements, but returns the full per-element boolean array instead of reducing it down to one combined result — which lets you see exactly which elements matched and which didn't, rather than only knowing whether all of them did. np.allclose(a, b) is functionally equivalent to applying np.all() to the result of np.isclose(a, b).
Use np.isclose() over np.allclose() specifically when you need to know which particular elements differ, not just whether the arrays match overall — allclose() is essentially isclose() with an extra np.all() applied on top.
import numpy as np
a = np.array([1.0, 2.0, 3.00001])
b = np.array([1.0, 2.0001, 3.0])
print(np.isclose(a, b))2Practical Example
Here is a real-world application of np.isclose() showing how it is used in production NumPy code.
import numpy as np
a = np.array([1.0, 2.0, 3.00001])
b = np.array([1.0, 2.0001, 3.0])
mismatches = np.where(~np.isclose(a, b))
print(mismatches)3Best Practices
Follow these guidelines when working with np.isclose():
1. Use np.isclose() instead of allclose() when you need per-element detail about which values matched and which didn't
2. Combine np.isclose() with boolean indexing to isolate and inspect specifically the elements that failed a tolerance check
3. Adjust rtol/atol deliberately based on your data's expected precision, the same considerations that apply to allclose()
Tip: Use np.isclose() over np.allclose() specifically when you need to know which particular elements differ, not just whether the arrays match overall — allclose() is essentially isclose() with an extra np.all() applied on top.
import numpy as np
a = np.array([1.0, 2.0, 3.00001])
b = np.array([1.0, 2.0001, 3.0])
print(np.isclose(a, b))