📌  相关文章
📜  将给定 NumPy 数组中所有元素的角度从度数转换为弧度

📅  最后修改于: 2022-05-13 01:55:21.291000             🧑  作者: Mango

将给定 NumPy 数组中所有元素的角度从度数转换为弧度

角度可以用度数和弧度表示。在本文中,我们将了解将度数转换为弧度的方法和方法。

方法#1:使用弧度()

此方法将一个数组作为输入参数,并返回一个具有弧度值的数组。

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)


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)


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)


输出:

方法 #2:使用deg2rad()

此方法接受输入数组并返回一个弧度值与输入数组大小相同的数组。

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)

输出:

方法 3:使用公式

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)

输出: