Friday, September 5, 2025
HomeLanguagesConvert angles from degrees to radians for all elements in a given...

Convert angles from degrees to radians for all elements in a given NumPy array

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




# python code demonstrating usage of radians
# method to convert degrees to radians
# importing numpy library
import numpy as np
import math
  
  
# initialising an array
array=np.arange(20.)*90
  
# printing degree values
print('Values of array in Degrees:',array)
  
# converting to radians
radian_array=np.radians(array)
  
# printing radian values
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




# python code demonstrating usage of radians
# method to convert degrees to radians
# importing numpy library
import numpy as np
import math
  
# initialising an array
array=np.arange(20.)*90
  
# printing degree values
print('Values of array in Degrees:',array)
  
# converting to radians
radian_array=np.deg2rad(array)
  
# printing radian values
print('Values of array in radians:',radian_array)


Output:

Method 3: Using Formula

Python3




# python code demonstrating usage of radians
# method to convert degrees to radians
# importing numpy library
import numpy as np
import math
  
# initialising an array
array=np.arange(20.)*90
  
# printing degree values
print('Values of array in Degrees:',array)
radian_array=[]
  
# converting to radians
for i in array:
    radian_array.append(i*math.pi/180)
  
# printing radian values
print('Values of array in radians:',radian_array)


Output:

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32264 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6634 POSTS0 COMMENTS
Nicole Veronica
11801 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11863 POSTS0 COMMENTS
Shaida Kate Naidoo
6750 POSTS0 COMMENTS
Ted Musemwa
7025 POSTS0 COMMENTS
Thapelo Manthata
6701 POSTS0 COMMENTS
Umr Jansen
6718 POSTS0 COMMENTS