The Python numpy radians is a trigonometric function to convert the angles from degrees to radians. For instance, 180 degrees = π and 360˚= 2π radians.
Syntax
The syntax of this mathematical method is
numpy.radians(a, axis = None, dtype = None, out = None)
Python numpy radians Example
In this example, we declared two one-dimensional ndarray of positive and negative numbers. Next, this method returns the radians for the given degrees.
import numpy as np a = np.array([360, 180, 90, 45, -360, -120]) print(a) b = np.radians(a) print(b)
[ 360 180 90 45 -360 -120]
[ 6.28318531 3.14159265 1.57079633 0.78539816 -6.28318531 -2.0943951 ]
Two-Dimensional example
In this program, we will declare a two-dimensional array of random values using the randn and randint methods and find its radians.
In the last line, we used out and dtype arguments to change the data type and save the result in a separate array.
import numpy as np a = np.random.randn(2, 3) * 15 print(a) b = np.radians(a) print(b) c = np.random.randint(600, 1500, size = 5) print(c) d = np.radians(c) print(d) x = np.arange(5.) np.radians(c, out = x, dtype = np.float16) print(x)
[[ 2.86679441 9.87068155 5.03262747]
[-15.49569423 -5.01291852 -9.7127809 ]]
[[ 0.050035 0.17227589 0.08783592]
[-0.27045088 -0.08749193 -0.16952001]]
[1172 877 641 1172 815]
[20.45525883 15.30653754 11.18756051 20.45525883 14.2244334 ]
[20.453125 15.3046875 11.1875 20.453125 14.2265625]