[Python] What is the role of rtol in numpy's isclose function?

Discussão em 'Python' iniciado por Stack, Abril 19, 2025.

  1. Stack

    Stack Membro Participativo

    In numpy.isclose() and numpy.allclose() there are two tolerance factors used to determine if two arrays are close enough to count as the same. There is the relative tolerance rtol and absolute tolerance atol. The default values are rtol=1e-05 and atol=1e-08.

    Quoting the documentation:


    For finite values, isclose uses the following equation to test whether two floating point values are equivalent.:

    absolute(a - b) <= (atol + rtol * absolute(b))
    ​

    Mathematically I understand this, but I am confused about the point of rtol. Why not just use a single tolerance value tol, and if |a-b| < tol, then return False? Obviously, following the above equation, I could just do this manually by setting rtol to zero, thereby making everything symmetric. What is the point of the symmetry-breaking rtol factor?

    Related question
    How allclose() works?

    Continue reading...

Compartilhe esta Página