Python:将度转换为弧度-不工作
我已经尝试用Python和numpy做了以下工作,但我的答案并不是我想要的值。我想要Python:将度转换为弧度-不工作,python,numpy,math,Python,Numpy,Math,我已经尝试用Python和numpy做了以下工作,但我的答案并不是我想要的值。我想要cos(30)=0.866 import math import numpy as np print(math.degrees(np.cos(30))) print(np.cos(math.degrees(30))) print(math.degrees(math.cos(30))) print(math.cos(math.degrees(30))) 任何帮助都将不胜感激,谢谢你数学。度将弧度转换为度,但你显
cos(30)=0.866
import math
import numpy as np
print(math.degrees(np.cos(30)))
print(np.cos(math.degrees(30)))
print(math.degrees(math.cos(30)))
print(math.cos(math.degrees(30)))
任何帮助都将不胜感激,谢谢你
数学。度
将弧度转换为度,但你显然是在给它度,你想使用数学。弧度
将度转换为弧度
print(np.cos(math.radians(30))
python math.cos期望角度以弧度为单位。所以你首先要把度变成弧度
radian = math.radians(30)
print(math.cos(radian))
# 0.866025403784
仅使用
数学
模块
import math
print(math.cos(math.radians(30)))
>>0.8660254037844387
试试这个:
from math import cos, radians
print(cos(radians(30)))
输出:
0.8660254037844387
手动进近:
import math
def to_radian(degree):
return degree * math.pi/180
print(math.cos(to_radian(30)))
Out[0]: 0.866025403784
打印(np.cos(数学弧度(30)))
。