Wednesday, April 11, 2018

Python - calculate arctangent in radians and degrees

We know that the arctangent of 1 is 45 degrees or pi/4 radians. Now, let see how we can calculate the value using python:

Using Numpy:

import numpy
import math
numpy.arctan(1) # calculates in radians
0.78539816339744828
numpy.arctan(1)*180/math.pi # calculates in degrees
45.0

Using regular python:

import math
math.atan(1) # calculates in radians
0.7853981633974483
math.atan(1)*180/math.pi # calculates in degrees
45.0





References:
https://docs.scipy.org/doc/numpy/reference/generated/numpy.arctan.html
https://docs.python.org/2/library/math.html#math.atan

No comments:

Post a Comment