- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Compute element-wise arc tangent of x1/x2 choosing the quadrant correctly in Python

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).

The 1st parameter is the y-coordinates. The 2nd parameter is the x-coordinates. If x1.shape != x2.shape, they must be broadcastable to a common shape. The method returns array of angles in radians, in the range [-pi, pi]. This is a scalar if both x1 and x2 are scalars.

## Steps

At first, import the required library −

import numpy as np

Creating arrays using the array() method. These are four points in different quadrants −

x = np.array([-1, +1, +1, -1]) y = np.array([-1, -1, +1, +1])

Display the array1 −

print("Array1 (x coordinates)...\n", x)

Display the array2 −

print("\nArray2 (y coordinates)...\n", y)

To compute element-wise arc tangent of x1/x2 choosing the quadrant correctly, use the numpy, arctan2() method in Python −

print("\nResult...",np.arctan2(y, x) * 180 / np.pi)

## Example

import numpy as np # 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). # Creating arrays using the array() method # These are four points in different quadrants x = np.array([-1, +1, +1, -1]) y = np.array([-1, -1, +1, +1]) # Display the array1 print("Array1 (x coordinates)...\n", x) # Display the array2 print("\nArray2 (y coordinates)...\n", y) # To compute element-wise arc tangent of x1/x2 choosing the quadrant correctly, use the numpy, arctan2() method in Python print("\nResult...",np.arctan2(y, x) * 180 / np.pi)

## Output

Array1 (x coordinates)... [-1 1 1 -1] Array2 (y coordinates)... [-1 -1 1 1] Result... [-135. -45. 45. 135.]

- Related Questions & Answers
- Compute the Hyperbolic tangent in Python
- Number of integral solutions of the equation x1 + x2 +…. + xN = k in C++
- Compute the inverse Hyperbolic tangent in Python
- Compute the bit-wise XOR of two Numpy arrays element-wise
- Compute the bit-wise OR of two Numpy arrays element-wise
- Compute the Hyperbolic tangent of the array elements in Python
- Compute the bit-wise NOT of an array element-wise in Numpy
- Compute the bit-wise AND of two arrays element-wise in Numpy
- Compute the inverse Hyperbolic tangent of array elements in Python
- Compute the bit-wise OR of two boolean arrays element-wise in Numpy
- Compute the bit-wise AND of two boolean arrays element-wise in Numpy
- Compute the bit-wise XOR of two boolean arrays element-wise in Numpy
- Get the arc tangent of a given value in Java
- Compute the inverse hyperbolic tangent with scimath in Python
- Compute the bit-wise XOR of two One-Dimensional Numpy arrays element-wise