Python NumPy angle() Function

NumPy angle() Function:

The angle() method of the NumPy module returns the element-wise angle of the complex argument.

Syntax:

numpy.angle(a, deg=False)

Parameters

a: This is required. It is an array given as input.

deg: This is optional. If True, it returns the angle in degrees; if False, returns the angle in radians which is the default.

Return Value: 

The element-by-element angle of the complex argument is returned by the angle() method of the NumPy module.

NumPy angle() Function in Python

Example1: (In degrees)

Approach:

  • Import numpy module using the import keyword
  • Pass some random complex numbers list(n-Dimensional) as an argument to the
    array() function to create an array.
  • Store it in a variable.
  • Print the above-given array.
  • Pass the above-given array, deg as True as the arguments to the angle() function of the numpy module to get the angle of all the elements of the given array in degrees.
  • Store it in another variable.
  • Print the angle of all the elements of the given array in degrees.
  • The Exit of the Program.

Below is the implementation:

# Import numpy module using the import keyword
import numpy as np
# Pass some random complex numbers list(n-Dimensional) as an argument to the 
# array() function to create an array. 
# Store it in a variable.
gvn_arry = np.array([[1+3j, 2+3j],
                     [2+4j, 1+2j]])           
# Print the above given array.
print("The above given array is:")
print(gvn_arry)
print()
# Pass the above given array, deg as True as the arguments to the angle() 
# function of the numpy module to get the angle of all the elements of
# the given array in degrees
# Store it in another variable.
rslt = np.angle(gvn_arry, deg=True)
# Print the angle of all the elements of the given array in degrees.
print("The angle of all the elements of the given array in degrees:")
print(rslt)

Output:

The above given array is:
[[1.+3.j 2.+3.j]
[2.+4.j 1.+2.j]]

The angle of all the elements of the given array in degrees:
[[71.56505118 56.30993247]
[63.43494882 63.43494882]]

Example2: (In radians)

Approach:

  • Import numpy module using the import keyword
  • Pass some random complex numbers list(n-Dimensional) as an argument to the
    array() function to create an array.
  • Store it in a variable.
  • Print the above-given array.
  • Pass the above-given array, deg as False as the arguments to the angle() function of the numpy module to get the angle of all the elements of the given array in radians.
  • Store it in another variable.
  • Print the angle of all the elements of the given array in radians.
  • The Exit of the Program.

Below is the implementation:

# Import numpy module using the import keyword
import numpy as np
# Pass some random complex numbers list(n-Dimensional) as an argument to the 
# array() function to create an array. 
# Store it in a variable.
gvn_arry = np.array([[1+3j, 2+3j],
                     [2+4j, 1+2j]])           
# Print the above given array.
print("The above given array is:")
print(gvn_arry)
print()
# Pass the above given array, deg as False as the arguments to the angle() 
# function of the numpy module to get the angle of all the elements of
# the given array in Radians
# Store it in another variable.
rslt = np.angle(gvn_arry, deg=False)
# Print the angle of all the elements of the given array in Radians.
print("The angle of all the elements of the given array in Radians:")
print(rslt)

Output:

The above given array is:
[[1.+3.j 2.+3.j]
[2.+4.j 1.+2.j]]

The angle of all the elements of the given array in Radians:
[[1.24904577 0.98279372]
[1.10714872 1.10714872]]

NOTE: 

If you do not give the ‘deg’ argument it gives the angle in radians by default.