pythonnumpy

What is the difference between numpy.atan and numpy.arctan?


When looking for the 2-pi range version of np.atan (which turns out to be np.atan2) I found that there's a np.arctan as well - is there some difference between np.arctan and np.atan? The test below doesn't seem to show any difference between atan and arctan , or between atan2 and arctan2:

import numpy as np
for i in np.arange(0,2*np.pi,.1):
    x = np.cos(i)
    y = np.sin(i)
    th = np.atan(y/x)
    th2 = np.atan2(y,x)
    th3 = np.arctan(y/x)
    th4 = np.arctan2(y,x)
    print(f'atan {th} atan2 {th2} arctan {th3} arctan2 {th4}')

Solution

  • numpy.atan is one of the aliases added to the NumPy main namespace in NumPy 2.0 as part of NEP 56, a drive to support a shared standard interface for Python array libraries. It is exactly the same object as numpy.arctan.

    It is not present before NumPy 2.0. If you still need to support 1.x versions of NumPy, you should stick to numpy.arctan until you no longer have this support requirement.