The confusing part is that the equation shows both parameters being used at the same time. Look at it like this instead:

  • Usecase 1: absolute tolerance (atol): absolute(a - b) <= atol
  • Usecase 2: relative tolerance (rtol): absolute(a - b) <= rtol * absolute(b)

An alternative way to implement both with a single tolerance parameter would be to add a flag that determines if the tolerance is relative or absolute. Separating the use-cases like that breaks down in the usecase where array values can be both large and zero. If only one array can have zeros, make that one a and use the asymmetrical equation to your benefit without atol. If either one can have zeros, simply set rtol to some acceptable value for large elements, and set atol to the value you want to kick in for zeros.

You generally want to use rtol: since the precision of numbers and calculations is very much finite, larger numbers will almost always be less precise than smaller ones, and the difference scales linearly (again, in general). You use atol for numbers that are so close to zero that rounding errors are liable to be larger than the number itself, or when the reference number can be zero.

Another way to look at it is atol compares fixed decimal places, while rtol compares significant figures.

A caveat is that both of the default values of the function are non-zero: rtol=1e-05 and atol=1e-08. That means that if you want to use only one or the other of them, you must explicitly set the other to zero.

Answer from Mad Physicist on Stack Overflow
🌐
NumPy
numpy.org › doc › stable › reference › generated › numpy.isclose.html
numpy.isclose — NumPy v2.5 Manual
numpy.isclose(a, b, rtol=1e-05, atol=1e-08, equal_nan=False)[source]# Returns a boolean array where two arrays are element-wise equal within a tolerance. The tolerance values are positive, typically very small numbers. The relative difference (rtol * abs(b)) and the absolute difference atol ...
Top answer
1 of 3
32

The confusing part is that the equation shows both parameters being used at the same time. Look at it like this instead:

  • Usecase 1: absolute tolerance (atol): absolute(a - b) <= atol
  • Usecase 2: relative tolerance (rtol): absolute(a - b) <= rtol * absolute(b)

An alternative way to implement both with a single tolerance parameter would be to add a flag that determines if the tolerance is relative or absolute. Separating the use-cases like that breaks down in the usecase where array values can be both large and zero. If only one array can have zeros, make that one a and use the asymmetrical equation to your benefit without atol. If either one can have zeros, simply set rtol to some acceptable value for large elements, and set atol to the value you want to kick in for zeros.

You generally want to use rtol: since the precision of numbers and calculations is very much finite, larger numbers will almost always be less precise than smaller ones, and the difference scales linearly (again, in general). You use atol for numbers that are so close to zero that rounding errors are liable to be larger than the number itself, or when the reference number can be zero.

Another way to look at it is atol compares fixed decimal places, while rtol compares significant figures.

A caveat is that both of the default values of the function are non-zero: rtol=1e-05 and atol=1e-08. That means that if you want to use only one or the other of them, you must explicitly set the other to zero.

2 of 3
9

Which tolerance(s) to use depends on your problem statement. For example, what if my array has a wide domain of values, ranging from 1e-10 to 1e10? A small atol would work well for small values, but poorly for large values, and vice-versa for a large atol. But rtol is perfect in this case because I can specify that the acceptable delta should scale with each value.

🌐
NumPy
numpy.org › doc › 2.1 › reference › generated › numpy.isclose.html
numpy.isclose — NumPy v2.1 Manual
numpy.isclose(a, b, rtol=1e-05, atol=1e-08, equal_nan=False)[source]# Returns a boolean array where two arrays are element-wise equal within a tolerance. The tolerance values are positive, typically very small numbers. The relative difference (rtol * abs(b)) and the absolute difference atol ...
🌐
NumPy
numpy.org › doc › 1.25 › reference › generated › numpy.isclose.html
numpy.isclose — NumPy v1.25 Manual
numpy.isclose(a, b, rtol=1e-05, atol=1e-08, equal_nan=False)[source]# Returns a boolean array where two arrays are element-wise equal within a tolerance. The tolerance values are positive, typically very small numbers. The relative difference (rtol * abs(b)) and the absolute difference atol ...
🌐
NumPy
numpy.org › devdocs › reference › generated › numpy.isclose.html
numpy.isclose — NumPy v2.6.dev0 Manual
numpy.isclose(a, b, rtol=1e-05, atol=1e-08, equal_nan=False)[source]# Returns a boolean array where two arrays are element-wise equal within a tolerance. The tolerance values are positive, typically very small numbers. The relative difference (rtol * abs(b)) and the absolute difference atol ...
🌐
NumPy
numpy.org › doc › 2.3 › reference › generated › numpy.isclose.html
numpy.isclose — NumPy v2.3 Manual
numpy.isclose(a, b, rtol=1e-05, atol=1e-08, equal_nan=False)[source]# Returns a boolean array where two arrays are element-wise equal within a tolerance. The tolerance values are positive, typically very small numbers. The relative difference (rtol * abs(b)) and the absolute difference atol ...
🌐
Medium
medium.com › @amit25173 › what-is-numpy-isclose-and-when-to-use-it-55375f4bc9f6
What is numpy.isclose and When to Use It? | by Amit Yadav | Medium
February 9, 2025 - While they aren’t exactly the same, they’re pretty close, right? That’s what numpy.isclose is for—tolerating those tiny, insignificant differences. ... rtol (Relative Tolerance): Think of this as the percentage wiggle room.
🌐
SciPy
docs.scipy.org › doc › › numpy-1.9.2 › reference › generated › numpy.isclose.html
numpy.isclose — NumPy v1.9 Manual
The relative difference (rtol * abs(b)) and the absolute difference atol are added together to compare against the absolute difference between a and b. ... New in version 1.7.0. For finite values, isclose uses the following equation to test whether two floating point values are equivalent.
🌐
GitHub
github.com › numpy › numpy › issues › 25550
DOC: What is the mathematical theory or idea behind numpy.isclose? · Issue #25550 · numpy/numpy
January 8, 2024 - Issue with current documentation: I'm trying to find the theory of formula behind numpy.isclose(). According to pytorch document and here: ∣input−other∣≤ atol + rtol×∣other∣ I search something like "relative tolerance in numerical analys...
Author: numpy
Find elsewhere
🌐
NumPy
numpy.org › doc › stable › reference › generated › numpy.allclose.html
numpy.allclose — NumPy v2.5 Manual
The tolerance values are positive, typically very small numbers. The relative difference (rtol * abs(b)) and the absolute difference atol are added together to compare against the absolute difference between a and b.
🌐
NumPy
numpy.org › doc › 2.4 › reference › generated › numpy.isclose.html
numpy.isclose — NumPy v2.4 Manual
numpy.isclose(a, b, rtol=1e-05, atol=1e-08, equal_nan=False)[source]# Returns a boolean array where two arrays are element-wise equal within a tolerance. The tolerance values are positive, typically very small numbers. The relative difference (rtol * abs(b)) and the absolute difference atol ...
🌐
GitHub
github.com › numpy › numpy › issues › 10161
numpy.isclose vs math.isclose · Issue #10161 · numpy/numpy
December 5, 2017 - numpy.isclose (https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.isclose.html): abs(a - b) <= (atol + rtol * abs(b)) math.isclose (https://docs.python.org/3/library/math.html#math.isclose): abs(a - b) <= max(rtol * max(abs(a), abs(b)), atol) Note that Numpy's equation is not symmetric and correlates the atol and rtol parameters, both are bad things (IMO).
Author: numpy
Top answer
1 of 2
4

I know that the whole XY problem ...

No, there is no XY problem in the question!

The question asks about the function and its parameter. A fact that there is another, "more basic" function with the parameter of the similar meaning doesn't make the problem to be XY. Do not confuse generalization with XY.

For better SEO ... I edited the question

SEO is quite indifferent to the title. It equally finds a question for any matched word in the question body. Moreover, it will be able to find a allclose-only question for isclose search just because these words a "similar" (in some sense).

We edit a title and a question body not for SEO, but for the future readers themselves. For reader it is sufficient to find the same parameter name for look closer to the question. Even if a reader is not aware that functions allclose and isclose are about very similar things, they will find the first paragraph to have a lot of sense for isclose function too.


In total: There is no fundamental problems with the question. It asks about meaning of the specific parameter in the specific function. And does that in the form, which can be easily applied to other function(s) with the same parameter. The answers describe the parameter meaning in a function-agnostic form. The search will find the question even for a string containing another function name.

2 of 2
4

Your edit was inappropriate, plain and simple. You outright changed the function that OP was asking about. Edits to questions should basically only ever be done to make the question more clear or easier to understand. If you're the asker, that could include adding code, errors, etc. that only you have access to. If you're not the asker, that means you're basically limited to formatting, grammar, spelling, and readability edits only.

You instead changed what the question was asking about altogether. You even had to edit the documentation quote to reflect the new thing you made the question ask about. That's an inappropriate edit any day of the week, even if the constituent part of the function (rtol) is used the same in the new function you asked about as the old function the asker originally asked about.

but reverting to the previous revision without trying to take any single bit from the edit is not cool and behavior like this stops people from contributing to StackOverflow [sic] and cleaning it up.

If your edit had been an improvement, then I'd agree with you. But the onus is on the editor to make sure their edit only improves the question, not changes it completely. A rollback is the appropriate action for such an edit. What's "not cool" is when someone changes a question to ask something completely different, and then gets upset when the question author undoes that change.

🌐
JAX Documentation
docs.jax.dev › en › latest › _autosummary › jax.numpy.isclose.html
jax.numpy.isclose — JAX documentation
jax.numpy.isclose(a, b, rtol=1e-05, atol=1e-08, equal_nan=False)[source]# Check if the elements of two arrays are approximately equal within a tolerance. JAX implementation of numpy.allclose(). Essentially this function evaluates the following condition: \[|a - b| \le \mathtt{atol} + \mathtt{rtol} ...
🌐
NumPy
numpy.org › doc › 2.0 › reference › generated › numpy.isclose.html
numpy.isclose — NumPy v2.0 Manual
numpy.isclose(a, b, rtol=1e-05, atol=1e-08, equal_nan=False)[source]# Returns a boolean array where two arrays are element-wise equal within a tolerance. The tolerance values are positive, typically very small numbers. The relative difference (rtol * abs(b)) and the absolute difference atol ...
🌐
NumPy
numpy.org › doc › 1.19 › reference › generated › numpy.isclose.html
numpy.isclose — NumPy v1.19 Manual
June 29, 2020 - numpy.isclose(a, b, rtol=1e-05, atol=1e-08, equal_nan=False)[source]¶ · Returns a boolean array where two arrays are element-wise equal within a tolerance. The tolerance values are positive, typically very small numbers. The relative difference (rtol * abs(b)) and the absolute difference ...
🌐
Python Pool
pythonpool.com › home › blog › numpy isclose explained with examples in python
NumPy isclose Explained with examples in Python - Python Pool
June 14, 2021 - numpy.isclose(a,b) This is the general syntax for our function. Now in the next section, let us look at the various parameters associated with it. 1. a,b : array_like · This parameter represents the 2 input arrays that need to be compared. 2. rtol:float · This parameter represents the relative tolerance parameter.
🌐
NumPy
numpy.org › doc › 2.2 › reference › generated › numpy.isclose.html
numpy.isclose — NumPy v2.2 Manual
numpy.isclose(a, b, rtol=1e-05, atol=1e-08, equal_nan=False)[source]# Returns a boolean array where two arrays are element-wise equal within a tolerance. The tolerance values are positive, typically very small numbers. The relative difference (rtol * abs(b)) and the absolute difference atol ...