Python numpy.sin 函数的度数?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28077733/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 02:42:54  来源:igfitidea点击:

numpy.sin function in degrees?

pythonmathnumpytrigonometry

提问by Daniil Ukhorskiy

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() 函数。我曾尝试使用 numpy.degrees() 和 numpy.rad2deg()。

numpy.sin(90)

numpy.degrees(numpy.sin(90))

Both return ~ 0.894 and ~ 51.2 respectively.

两者分别返回 ~ 0.894 和 ~ 51.2。

Thanks for your help.

谢谢你的帮助。

采纳答案by BrenBarn

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

您不想转换度数,因为您已经有了度为单位的数字 (90)。您需要将 90度数转换为弧度,并且需要取正弦之前进行:

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

(You can use either deg2rador radians.)

(您可以使用deg2radradians。)

回答by Malik Brahimi

Use the mathmodule from the standard Python library:

使用math标准 Python 库中的模块:

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