.deg2rad()
Anonymous contributor
Published Dec 16, 2024
Contribute to Docs
In NumPy, the .deg2rad()
function converts an angle from degrees to radians.
Note: In NumPy, the default unit for angles is radians. Therefore, the
.deg2rad()
function is used to convert angle values from degrees to radians.
Syntax
numpy.deg2rad(x, out=None)
x
: The input array (or scalar) containing angles in degrees that need to be converted to radians.out
(Optional): A location where the result is stored. If not specified, a new array is returned.
Example
In this example, the code converts an angle measured in degrees to radians using the numpy.deg2rad()
function:
import numpy as np# Angle of the board on a table measured in degreesangle_degrees = 45# Convert the angle to radiansangle_radians = np.deg2rad(angle_degrees)# Output the resultprint(f"Angle in degrees: {angle_degrees}")print(f"Angle in radians: {angle_radians}")
The code above produces the following output:
Angle in degrees: 45Angle in radians: 0.7853981633974483
Codebyte Example
Run the codebyte example below to understand how the .deg2rad()
function works:
All contributors
- Anonymous contributor
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn Python:NumPy on Codecademy
- Career path
Computer Science
Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!Includes 6 CoursesWith Professional CertificationBeginner Friendly75 hours - Course
Learn Python 3
Learn the basics of Python 3.12, one of the most powerful, versatile, and in-demand programming languages today.With CertificateBeginner Friendly23 hours