Python
numpy

pi and arctan2 in numpy

Z = np.random.random((10,2))
print(Z)
X,Y = Z[:,0], Z[:,1]
print(X)
print(Y)
print(np.tan(np.pi/4))
t = np.arctan2(np.sqrt(3),1)
r = t*3
print(np.pi, r)
print(np.allclose(np.pi, r))
R = np.sqrt(X**2+Y**2)
T = np.arctan2(Y,X)
print(R)
print(T)
print(T/np.pi)
  • e.g.
[[ 0.3059635   0.11279336]
 [ 0.99213694  0.70904914]
 [ 0.4863001   0.59119289]
 [ 0.17257894  0.86010688]
 [ 0.16350432  0.67312375]
 [ 0.72789583  0.41819254]
 [ 0.27758441  0.43846711]
 [ 0.52287092  0.78472806]
 [ 0.60692598  0.44147906]
 [ 0.72934469  0.70356892]]
[ 0.3059635   0.99213694  0.4863001   0.17257894  0.16350432  0.72789583
  0.27758441  0.52287092  0.60692598  0.72934469]
[ 0.11279336  0.70904914  0.59119289  0.86010688  0.67312375  0.41819254
  0.43846711  0.78472806  0.44147906  0.70356892]
1.0
(3.141592653589793, 3.1415926535897931)
True
[ 0.32609202  1.21946152  0.76550429  0.87724988  0.69269708  0.83947445
  0.5189475   0.94296984  0.75050843  1.01338685]
[ 0.35319171  0.62050298  0.88244131  1.37277753  1.33250751  0.52147536
  1.00640832  0.98304178  0.62888071  0.76741174]
[ 0.11242441  0.19751223  0.28088979  0.43696866  0.42415031  0.16599076
  0.32034972  0.31291192  0.20017895  0.24427474]

Refs.