How to use the numpy.degrees function in Python
The numpy.degrees() function
The numpy.degrees() function in Python is a mathematical function that allows us to convert radians to degrees.
Syntax
numpy.degrees(x,out=None)
Parameters
x: This represents the input array in radians.out: This represents where the result is stored.
Return type
The numpy.degrees() function returns the corresponding array with degree values.
Example
The following code shows us how to use the numpy.degrees() function in Python:
# import numpyimport numpy as npimport math# create a listarr = [0, math.pi/2,math.pi/6,8,math.pi/4 ]print(f"Original array before the np.unwrap(): {arr}")# compute the degree value for each element and store itarr_degrees = np.degrees(arr)print("After the np.degrees()")print(arr_degrees)
Explanation
-
Lines 2–3: We import the
numpyandmathlibraries . -
Line 6: We create a list called
arr. -
Line 7: We display the elements in the list
arr. -
Line 9: We use the
np.degrees()function to return the corresponding array with degree values. -
Lines 10–11: We display the result.