Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

numpy.sin function in degrees?

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.

like image 782
Daniil Ukhorskiy Avatar asked Jan 21 '15 22:01

Daniil Ukhorskiy


People also ask

Is numpy sin in radians?

sin. Trigonometric sine, element-wise. Angle, in radians ( rad equals 360 degrees).

How do you write sin in numpy?

sin() in Python. numpy. sin(x[, out]) = ufunc 'sin') : This mathematical function helps user to calculate trigonometric sine for all x(being the array elements).


2 Answers

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

like image 124
BrenBarn Avatar answered Sep 20 '22 00:09

BrenBarn


Use the math module from the standard Python library:

>>> math.sin(math.radians(90)) 
like image 42
Malik Brahimi Avatar answered Sep 21 '22 00:09

Malik Brahimi