10. Write a Python Numpy program to convert the angles from radians to degrees.
The output is:
a = [-np.pi*2, -np.pi*3/2, -np.pi, -np.pi/2, np.pi/2, np.pi, np.pi*3/2, np.pi*2]
Expected Answer:
Initial angles in radians:
[-6.28318531 -4.71238898 -3.14159265 -1.57079633 1.57079633 3.14159265
4.71238898 6.28318531]
Convert to degrees:
[-360. -270. -180. -90. 90. 180. 270. 360.]
Sample Answer:
import numpy as np
a = np.array([-np.pi*2, -np.pi*3/2, -np.pi, -np.pi/2, np.pi/2, np.pi, np.pi*3/2, np.pi*2])
r1 = np.degrees(a)
r2 = np.rad2deg(a)
assert np.array_equiv(r1, r2)
print('Initial angles in radians: ')
print(a)
print('\nConvert to degrees:')
print(r1)
More Exercises:
Python String ExercisesMore Numpy Exercises:
Numpy String ExercisesMore Pandas Exercises:
Pandas Series ExercisesMore Tutorials:
Python Installation - Linux (Ubuntu)