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 (TrueorFalse), indicating whether the returned angle should be in degrees (ifTrue) or in radians (ifFalse). 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 valuesz = np.array([1.0, 1.0j, 1+1j])# implementing the angle() functionmyarray = np.angle(z, deg=True)print(myarray)
Explanation
- Line 1: We import the
numpymodule. - Line 4: We use the
array()function to create an array,zwith complex values. - Line 7: We implement the
angle()function on the input array using theTruevalue for thedegargument. This is for our output array to be in degrees. We assign the result to a variable,myarray. - Line 9: We print
myarray.