Trusted answers to developer questions

How to use the numpy.degrees function in Python

Free System Design Interview Course

Many candidates are rejected or down-leveled due to poor performance in their System Design Interview. Stand out in System Design Interviews and get hired in 2024 with this popular free course.

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 numpy
import numpy as np
import math
# create a list
arr = [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 it
arr_degrees = np.degrees(arr)
print("After the np.degrees()")
print(arr_degrees)

Explanation

  • Lines 2–3: We import the numpy and math libraries .

  • 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.

RELATED TAGS

numpy
python3
python
Did you find this helpful?