numpy.sin function in degrees?

家住魔仙堡 提交于 2020-12-01 08:22:16

问题


I'm working on a problem that has to do with calculating angles of refraction and what not. However, it seems that I'm unable to use the numpy.sin() function in degrees. I have tried to use numpy.degrees() and numpy.rad2deg().

numpy.sin(90)

numpy.degrees(numpy.sin(90))

Both return ~ 0.894 and ~ 51.2 respectively.

Thanks for your help.


回答1:


You don't want to convert to degrees, because you already have your number (90) in degrees. You need to convert 90 from degrees to radians, and you need to do it before you take the sine:

>>> np.sin(np.deg2rad(90))
1.0

(You can use either deg2rad or radians.)




回答2:


Use the math module from the standard Python library:

>>> math.sin(math.radians(90))


来源:https://stackoverflow.com/questions/28077733/numpy-sin-function-in-degrees

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!