numpy.radians() Function:
Numpy degrees to radians: The numpy.radians() function is a mathematical function that converts angles from degrees to radians.
Syntax:
numpy.radians(x, out = ufunc ‘radians’)
Parameters
x: It is an array in degrees
out: This is optional. It is an ndarray. The output array has the same shape as “x.”
2*pi radians = 360 degrees
Return Value:
9.42477796: It Returns an array containing radian values instead of degree values.
Example
Approach:
- Import numpy module using the import keyword.
- Import math module using the import keyword.
- Give the array values for the arrange function and multiply it with 90 for conversion
- Print the above-given array values in degrees.
- Pass the given array to radians() function of numpy module to convert the array values to radians.
- Print the given array values after converting them into radians.
- The Exit of the Program.
Below is the implementation:
# Import numpy module using the import keyword import numpy as np # Import math module using the import keyword import math # Give the array values for the arrange function and multiply it with 90 for conversion gvn_arry = np.arange(8.) * 90 # Print the above given array values in degrees print ("The given array values in degrees:\n", gvn_arry) # Pass the given array to radians() function of numpy module to convert the # array values to radians rad_arry = np.radians(gvn_arry) # Print the given array values after converting into radians print ("The given array values after converting into radians:\n", rad_arry)
Output:
The given array values in degrees: [ 0. 90. 180. 270. 360. 450. 540. 630.] The given array values after converting into radians: [ 0. 1.57079633 3.14159265 4.71238898 6.28318531 7.85398163 9.42477796 10.99557429]
numpy deg2rad() Function
The deg2rad() function of the NumPy module converts angles from degrees to radians.
Syntax:
numpy.deg2rad(array, out)
Parameters
array: These are the angles for which the degree values must be computed.
out: It represents the output array’s shape(rows, cols).
Return Value:
An array of degree angles corresponding to the radian specified in the input array is returned.
Example
Approach:
- Import numpy module using the import keyword.
- Import math module using the import keyword.
- Give the list(array) as static input(here we get pi values using the math.pi) and store it in a variable.
- Print the above-given array values in degrees.
- Pass the given array to deg2rad() function of numpy module to convert the given array values to radians.
- Print the given array values after converting them into radians.
- The Exit of the Program.
Below is the implementation:
# Import numpy module using the import keyword import numpy as np # Import math module using the import keyword import math # Give the list as static input(here we get pi values using the math.pi) # and store it in a variable. gvn_arry = [0, math.pi/3, math.pi/4, math.pi/5 ] # Print the given array in degrees print ("The given array values in degrees:\n", gvn_arry) # Pass the given array to deg2rad() function of numpy module to convert the # given array values to radians rad_arry = np.deg2rad(gvn_arry) # Print the given array values after converting into radians print ("The given array values after converting into radians:\n", rad_arry)
Output:
The given array values in degrees: [0, 1.0471975511965976, 0.7853981633974483, 0.6283185307179586] The given array values after converting into radians: [0. 0.01827705 0.01370778 0.01096623]