numpy.arctan2() in Python (original) (raw)
Last Updated : 07 Jul, 2021
The numpy.arctan2() method computes element-wise arc tangent of arr1/arr2 choosing the quadrant correctly. The quadrant is chosen so that arctan2(x1, x2) 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 (x2, x1).
Syntax : numpy.arctan2(arr1, arr2, casting = ‘same_kind’, order = ‘K’, dtype = None, ufunc ‘arctan’)
Parameters :
arr1 : [array_like] real valued; y-coordinates
arr2 : [array_like] real valued; x-coordinates. It must match shape of y-coordinates.
out : [ndarray, array_like [OPTIONAL]] array of same shape as x.
where : [array_like, optional] True value means to calculate the universal functions(ufunc) at that position, False value means to leave the value in the output alone.
Note :
2pi Radians = 360 degrees
The convention is to return the angle z whose real part lies in [-pi/2, pi/2].
Return : Element-wise arc tangent of arr1/arr2. The values are in the closed interval [-pi / 2, pi / 2].
Code #1 : Working
Python3
import
numpy as np
arr1
=
[
-
1
,
+
1
,
+
1
,
-
1
]
arr2
=
[
-
1
,
-
1
,
+
1
,
+
1
]
ans
=
np.arctan2(arr2, arr1)
*
180
/
np.pi
print
(
"x-coordinates : "
, arr1)
print
(
"y-coordinates : "
, arr2)
print
(
"\narctan2 values : \n"
, ans)
Output :
x-coordinates : [-1, 1, 1, -1] y-coordinates : [-1, -1, 1, 1]
arctan2 values : [-135. -45. 45. 135.]
Code #2 : Working
Python3
import
numpy as np
a
=
np.arctan2([
0.
,
0.
, np.inf], [
+
0.
,
-
0.
, np.inf])
b
=
np.arctan2([
1.
,
-
1.
], [
0.
,
0.
])
print
(
"a : "
, a)
print
(
"b : "
, b)
Output :
a : [ 0. 3.14159265 0.78539816] b : [ 1.57079633 -1.57079633]
References :
https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.arctan2.html#numpy.arctan2
.
Similar Reads
- numpy.arctan() in Python numpy.arctan(x[, out]) = ufunc 'arctan') : This mathematical function helps user to calculate inverse tangent for all x(being the array elements). Parameters : array : [array_like]elements are in radians. out : [array_like]array of same shape as x. Note : 2pi Radians = 360 degrees The convention is 2 min read
- numpy.arctanh in Python() numpy.arctanh() : This mathematical function helps user to calculate inverse hyperbolic tangent, element-wise for all arr. Syntax : numpy.arctanh(arr, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, ufunc 'arctanh') Parameters : arr : array_like Input array. out : [ndarray, o 2 min read
- numpy.arcsin() in Python numpy.arcsin(x[, out]) = ufunc 'arcsin') : This mathematical function helps user to calculate inverse sine for all x(being the array elements). Parameters : array : [array_like]elements are in radians. out : [array_like]array of same shape as x. Return : An array with inverse sine of x for all x i.e 2 min read
- numpy.arcsinh() in Python numpy.arcsinh() : This mathematical function helps user to calculate inverse hyperbolic sine, element-wise for all arr. Syntax : numpy.arcsinh(arr, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, ufunc 'arcsinh') Parameters : arr : array_like Input array. out : [ndarray, opti 2 min read
- NumPy Array in Python NumPy (Numerical Python) is a powerful library for numerical computations in Python. It is commonly referred to multidimensional container that holds the same data type. It is the core data structure of the NumPy library and is optimized for numerical and scientific computation in Python. Table of C 2 min read
- numpy.arccos() in Python numpy.arccos(x[, out]) = ufunc 'arccos') : This mathematical function helps user to calculate inverse cos for all x(being the array elements). Parameters : array : [array_like]elements are in radians. out : [array_like]array of same shape as x. Note : 2pi Radians = 360 degrees The convention is to r 2 min read
- numpy.alen() in Python numpy.alen() function is used to return the length of the first dimension of the input array. Syntax : numpy.alen(arr) Parameters : arr : [array_like] Input array. Return : [int]Length of the first dimension of arr. Code #1 : # Python program explaining # alen() function import numpy as geek # input 1 min read
- numpy.arccosh() in Python numpy.arccosh() : This mathematical function helps user to calculate inverse hyperbolic cosine, element-wise for all arr. Syntax : numpy.arccosh(arr, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, ufunc 'arccosh') Parameters : arr : array_like Input array. out : [ndarray, op 2 min read
- numpy.asarray() in Python numpy.asarray()function is used when we want to convert input to an array. Input can be lists, lists of tuples, tuples, tuples of tuples, tuples of lists and arrays. Syntax : numpy.asarray(arr, dtype=None, order=None) Parameters : arr : [array_like] Input data, in any form that can be converted to a 2 min read
- numpy.angle() in Python numpy.angle() function is used when we want to compute the angle of the complex argument. A complex number is represented by “ x + yi " where x and y are real number and i= (-1)^1/2. The angle is calculated by the formula tan-1(x/y). Syntax : numpy.angle(z, deg=0) Parameters : z : [array_like] A com 2 min read