
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Convert Angles from Radians to Degrees in a NumPy Array
Degrees and Radians are the two units of measurement for the angles.
Degrees are the most commonly used unit of measurement for the angles. It is denoted by theta(Ã). There are 360 degrees in circle and each degree is divided into 60 minutes and each minute is further divided into 60 seconds. Mathematically the radians converted into degrees by multiplying the radian with 180/pi.
The Radians are the natural unit of measurement of the angles in physics, mathematics and engineering. Simply we can define the radians as the length of an arc of the circle to the radius of the circle. The circle has 2*pi radians. Mathematically the degrees can be converted into radians by multiplying the degrees with pi/180.
Converting radians to degrees using
We have a function in Numpy library named, degrees() to convert the angles from radians to degrees in a Numpy array.
Syntax
Following is the syntax for using the degrees() function to convert the radians to degrees.
numpy.degrees(array)
Where,
Numpy is the name of the library.
Degrees is the function used to convert the radians to degrees.
Array is the input array.
Example
In the following example, we have to pass the array to the degree() function to convert the radians to degrees.
import numpy as np arr = np.array([[23,34,65,87,3,4],[78,45,90,53,5,3]]) print("The created array:",arr) deg = np.degrees(arr) print("The conversion of radians to degrees:",deg)
Output
Following is the output of the degrees() functions of the Numpy library, when we execute the above code -
The created array: [[23 34 65 87 3 4] [78 45 90 53 5 3]] The conversion of radians to degrees: [[1317.8029288 1948.05650344 3724.22566835 4984.73281764 171.88733854229.18311805][4469.07080202 2578.31007809 5156.62015618 3036.67631419 286.47889757171.88733854]]
Example
Let's see another example to convert the radians into degrees by using the degrees() function.
import numpy as np arr = np.array([[[23,34,65,87,3,4],[78,45,90,53,5,3]],[[23,34,65,87,3,4],[78,45,90,53,5,3]]]) print("The created array:",arr) deg = np.degrees(arr) print("The conversion of radians to degrees:",deg)
Output
When we run the above code, we see the following output -
The created array: [[[23 34 65 87 3 4] [78 45 90 53 5 3]] [[23 34 65 87 3 4] [78 45 90 53 5 3]]] The conversion of radians to degrees: [[[1317.8029288 1948.05650344 3724.22566835 4984.73281764 171.88733854 229.18311805] [4469.07080202 2578.31007809 5156.62015618 3036.67631419 286.47889757 171.88733854]] [[1317.8029288 1948.05650344 3724.22566835 4984.73281764 171.88733854 229.18311805] [4469.07080202 2578.31007809 5156.62015618 3036.67631419 286.47889757 171.88733854]]]
Example
In the following example, we will convert the degrees into radians by using the radians() function of the numpy library.
import numpy as np arr = np.array([[[23,34,65,87,3,4],[78,45,90,53,5,3]],[[23,34,65,87,3,4],[78,45,90,53,5,3]]]) print("The created array:",arr) rad = np.radians(arr) print("The conversion of degrees to radians:",rad)
Output
When we run the above code, following output will be generated -
The created array: [[[23 34 65 87 3 4] [78 45 90 53 5 3]] [[23 34 65 87 3 4] [78 45 90 53 5 3]]] The conversion of degrees to radians: [[[0.40142573 0.59341195 1.13446401 1.51843645 0.05235988 0.06981317] [1.36135682 0.78539816 1.57079633 0.9250245 0.08726646 0.05235988]][[0.40142573 0.59341195 1.13446401 1.51843645 0.05235988 0.06981317] [1.36135682 0.78539816 1.57079633 0.9250245 0.08726646 0.05235988]]]