numpy.sin function in degrees?

PythonMathNumpyTrigonometry

Python Problem Overview


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.

Python Solutions


Solution 1 - Python

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.)

Solution 2 - Python

Use the math module from the standard Python library:

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

Solution 3 - Python

You can define the following symbols to work in degrees:

sind = lambda degrees: np.sin(np.deg2rad(degrees))
cosd = lambda degrees: np.cos(np.deg2rad(degrees))
print(sind(90)) # Output 1.0

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDaniil UkhorskiyView Question on Stackoverflow
Solution 1 - PythonBrenBarnView Answer on Stackoverflow
Solution 2 - PythonMalik BrahimiView Answer on Stackoverflow
Solution 3 - PythonFreemanView Answer on Stackoverflow