Convert angles from degrees to radians for all elements in a given NumPy array
Last Updated :
29 Aug, 2020
Angles can be expressed in both degrees and radians. In this article, we will know about the approaches and methods to convert degrees to radians.
Method #1 : Using radians()
This method takes an array as an input parameter and returns an array that has radian values.
Python
import numpy as np
import math
array = np.arange( 20. ) * 90
print ( 'Values of array in Degrees:' ,array)
radian_array = np.radians(array)
print ( 'Values of array in radians:' ,radian_array)
|
Output:
Method #2: Using deg2rad()
This method takes input array and returns an array that has radian values the same as the size of the input array.
Python3
import numpy as np
import math
array = np.arange( 20. ) * 90
print ( 'Values of array in Degrees:' ,array)
radian_array = np.deg2rad(array)
print ( 'Values of array in radians:' ,radian_array)
|
Output:
Method 3: Using Formula
Python3
import numpy as np
import math
array = np.arange( 20. ) * 90
print ( 'Values of array in Degrees:' ,array)
radian_array = []
for i in array:
radian_array.append(i * math.pi / 180 )
print ( 'Values of array in radians:' ,radian_array)
|
Output:
Share your thoughts in the comments
Please Login to comment...