cf.Data.arctan2¶
- classmethod Data.arctan2(x1, x2)[source]¶
Element-wise arc tangent of
x1/x2with correct quadrant.The quadrant (i.e. branch) is chosen so that
arctan2(y, x)is the signed angle in radians between the ray ending at the origin and passing through the point(1, 0), and the ray ending at the origin and passing through the point(x, y). (Note the role reversal: the “y-coordinate” is the first function parameter, the “x-coordinate” is the second.) By IEEE convention, this function is defined forx = +/-0and for either or both ofy = +/-infandx = +/-inf(see Notes for specific values).arctan2is identical to theatan2function of the underlying C library. The following special values are defined in the C standard:x1
x2
arctan2(x1, x2)+/- 0
+0
+/- 0
+/- 0
-0
+/- pi
> 0
+/-inf
+0 / +pi
< 0
+/-inf
-0 / -pi
+/-inf
+inf
+/- (pi/4)
+/-inf
-inf
+/- (3*pi/4)
Note that
+0and-0are distinct floating point numbers, as are+infand-inf.Added in version 3.16.0.
- Parameters:
- x1: array_like
Y coordinates.
- x2: array_like
X coordinates. x1 and x2 must be broadcastable to a common shape (which becomes the shape of the output). If both x1 and x2 have units, they must be equal or equivalent, in which case they will be conformed.
- Returns:
DataArray of angles in radians, in the range
(-pi, pi].
Examples
>>> import numpy as np >>> x = cf.Data([-1, +1, +1, -1]) >>> y = cf.Data([-1, -1, +1, +1]) >>> print((cf.Data.arctan2(y, x) * 180 / np.pi).array) [-135.0 -45.0 45.0 135.0] >>> x[1] = cf.masked >>> y[1] = cf.masked >>> print((cf.Data.arctan2(y, x) * 180 / np.pi).array) [-135.0 -- 45.0 135.0]
>>> print(cf.Data.arctan2([0, 0, np.inf], [+0., -0., np.inf]).array) [0.0 3.141592653589793 0.7853981633974483]
>>> print((cf.Data.arctan2([1, -1], [0, 0]) * 180 / np.pi).array) [90.0 -90.0]