Convert Radians to Degrees and Degrees to Radians in Python
In this blog we will learn how to convert the python degrees to radians and python radians to degrees
By convention every value you input in trigonometry functions in python will give output as radians to convert it into degrees
Code Convert Radians to Degrees :
import numpy as np
import matplotlib.pyplot as plt
t = np.linspace(0,360,360)
x = np.sin(np.radians(t)) #just type np.radians before defining input trignometry function variable
plt.plot(t,x)
What if i don't write np.radians
Then python will give output in radians as shown in code below
import numpy as np
import matplotlib.pyplot as plt
t = np.linspace(0,360,360)
x = np.sin((t))
plt.plot(t,x)
What if my values are in degrees but want to convert it into radians ?
import numpy as np
import matplotlib.pyplot as plt
x = np.sin(np.radians(45)) # value convert from radians to degrees
y = np.sin(np.degrees(x)) # value convert from degrees to radians in python
print(x)
Note :
- writing np.radians /np.degrees to convert the value in degrees/radians respectively look odd but this is the syntax or if you don't like it you can make your own function
0 Comments
if you are not getting it then ask i am glad to help