What is the numpy.radians() function in Python?

Overview

The numpy.radians() function in Python is used to convert the angles in a given array from degrees to radians.

Syntax

numpy.radians(x, /, out=None, *, where=True)

Parameter values

The numpy.radians() function takes the following parameter values:

  • x: This represents the input array in degrees. This parameter value is required for the function to work.
  • out: This represents a location where the result is stored. This is an optional parameter value.
  • where: This is the condition over which the input is broadcast. At a given location where this condition is True, the resulting array will be set to the ufunc result. Otherwise, the resulting array will retain its original value. This is also an optional parameter value.
  • **kwargs: This represents other keyword arguments. This is an optional parameter value.

Return type

The numpy.radians() function returns the corresponding radians of the degree values of the angles.

Code example

import numpy as np
# creating an array
x = np.array([30, 45, 60, 90, 180])
# converting the degrees to radians
myarray = np.radians(x)
print(myarray)

Code explanation

  • Line 1: We import the numpy module.
  • Line 4: We create an array, x, using the array() method.
  • Line 7: We implement the np.radians() function on the array. Then, we assign the result to a variable called myarray.
  • Line 9: We print the variable myarray to the console.

Free Resources