In Python, the numpy.arctan2()
function is used to return the element-wise arc tangent of , choosing the quadrant correctly.
numpy.arctan2(x1, x2, /, out=None, *, where=True)
This function takes the following parameter values:
x1
: This represents the y-coordinates.x2
: This represents the x-coordinates.out
: This represents a location where the result is stored. This is optional.where
: This is the condition over which the input is being broadcast. At a given location where this condition is True
, the resulting array is set to the ufunc
result. Otherwise, the resulting array retains its original value. This is optioanal.**kwargs
: This represents other keyword arguments.This function returns an array of angles in radians. The range of the values is [-pi, pi]
.
import numpy as np# creating an array representin the coordinatesx1 = np.array([4, 5])x2 = np.array([3, 12])# taking the arctan2 element-wisemyarray = np.arctan2(x1, x2)print(myarray)
numpy
module.x1
and x2
, representing the x and y coordinates, respectively.numpy.arctan2()
function on the arrays. The result is assigned to a variable, myarray
.myarray
.