Using np.isclose #2

Question Q6.1.8

Explain why the following evaluates to True even though the two approximations to $\pi$ differ by more than $10^{-16}$:

In [x]: np.isclose(3.1415926535897932, 3.141592653589793, atol=1.e-16, rtol=0)
Out[x]: True

whereas this statement works as expected:

In [x]: np.isclose(3.14159265358979, 3.1415926535897, atol=1.e-14, rtol=0)
Out[x]: False

Solution

To access solutions, please obtain an access code from Cambridge University Press at the Lecturer Resources page for my book (registration required) and then sign up to scipython.com providing this code.