np.radians: How to Convert Degrees to Radians in Python

The np.radians() is a library function that converts the angle from the degree to the radian. This means if we provide any value in degree, this function will help us to convert it into radian.

NumPy radians() is a mathematical function that helps the user to convert angles from degrees to radians.

Syntax

numpy.radians(arr[, out]) = ufunc ‘radians’)

Parameters

The radians() function takes up to two main parameters:

  1. arr: This is the array whose elements can be converted in radians from degrees.
  2. out: A position the result will be stored in. If the given, the shape to which the inputs broadcast must be in. If a freshly-allocated array is returned unless received or None. The tuple (possible as a keyword argument only) must have a length equal to the outputs.

Return Value

The radians() function returns an array of the same size as the input array, containing radian values inplace of degree values, but the return value will be in float data type.

Program to show the working of radians()

See the following code.

#Program to show working of radians()
import numpy as np

#declaring array
arr = [0, 30, 45, 60, 90]
#Printing array
print(arr)

#Now we will convert degrees to radians
arr1 = np.radians(arr)

#Printing radian values
print("New array is:")
print(arr1)

Output

[0.7853981633974483, 1.5707963267948966]
New array is:
[45. 90.]
The third angle is :  45.0

Explanation

In this program, we have initialized array values in degree. Then we printed them.

It was later converted to radian using the radians() function.

Program to find the value of 3rd angle of a triangle in radian

See the following code.

#Given values of two angles of triangle
#We have find the value of 3rd angle of the triangle in radian
import numpy as np
import math

#Assigning pi value in p
p = math.pi
#declaring array
arr = [30, 90]
#Printing array
print(arr)
#Now we will convert degrees to radians
arr1 = np.radians(arr)
#Printing radians values
print("New array is:")
print(arr1)

sum_two = np.sum(arr1)

#Printing value of third angle
print("The third angle is : ", p - sum_two, " radian")

Output

[30, 90]
New array is:
[0.52359878 1.57079633]
The third angle is :  1.0471975511965979  radian

Explanation

In this example, this program will calculate the third angle value in the radian of a rectangle when the values of the other two are provided. We have assigned radian values in the array and then printed the array with radian values.

Then we converted them into radians and calculated the sum of these two radians.

As we know, the total angle value of a rectangle is pi radian; we have subtracted the total sum from pi and printed the value of the 3rd angle in radians.

If we convert the radian into the degree, the degree will be 60.

Conclusion

To Convert Degrees to Radians in Python, use the np.radians() function.

That’s it.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.