What is the numpy.angle() function in NumPy?

Overview

The angle() function in NumPy obtains the angle of the complex argument passed to it.

Syntax

numpy.angle(z, deg=False)
The syntax for the angle() function in NumPy

Parameter value

The angle() function takes the following parameter values:

  • z: This represents the sequence number or the sequence of complex numbers whose angle is to be computed. This is a required parameter.
  • deg: This takes a Boolean value (True or False), indicating whether the returned angle should be in degrees (if True) or in radians (if False). This is an optional parameter.

Return value

The angle() function returns the complex argument's angle in the range, -pri, pi.

Example

import numpy as np
# creating an input array of complex values
z = np.array([1.0, 1.0j, 1+1j])
# implementing the angle() function
myarray = np.angle(z, deg=True)
print(myarray)

Explanation

  • Line 1: We import the numpy module.
  • Line 4: We use the array() function to create an array, z with complex values.
  • Line 7: We implement the angle() function on the input array using the True value for the deg argument. This is for our output array to be in degrees. We assign the result to a variable, myarray.
  • Line 9: We print myarray.

Free Resources