Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

function
numpy
python
communitycreator

# What is the numpy.arctan2() function in Python? Onyejiaku Theophilus Chidalu

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

### Overview

In Python, the numpy.arctan2() function is used to return the element-wise arc tangent of $\frac{x1}{x2}$, choosing the quadrant correctly.

### Syntax

numpy.arctan2(x1, x2, /, out=None, *, where=True)


### Parameter

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.

### Return value

This function returns an array of angles in radians. The range of the values is [-pi, pi].

### Code example

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)
Implementing the numpy.arctan2() function

### Explanation

• Line 1: We import the numpy module.
• Line 4–5: We create arrays, x1 and x2, representing the x and y coordinates, respectively.
• Line 8: We implement the numpy.arctan2() function on the arrays. The result is assigned to a variable, myarray.
• Line 10: We print the variable myarray.

RELATED TAGS

function
numpy
python
communitycreator

CONTRIBUTOR Onyejiaku Theophilus Chidalu

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring

Learn in-demand tech skills in half the time 