PyTorch .deg2rad()
Anonymous contributor
Published Jul 15, 2025
Contribute to Docs
In PyTorch, the .deg2rad() function converts angles from degrees to radians. This is especially useful when using trigonometric functions like torch.sin() or torch.cos(), which require input in radians.
Syntax
torch.deg2rad(input, *, out=None)
Parameters:
input: The input tensor containing angles in degrees.out(optional): The output tensor to store the result. If provided, the result is written to this tensor in-place.
Return value:
A tensor with the same shape as input, where each element is converted from degrees to radians. If out is specified, the returned tensor is the same as out.
Example
This example demonstrates the usage of the .deg2rad() function:
import torch# Define a tensor with angles in degreesdegrees = torch.tensor([0.0, 90.0, 180.0, 270.0])# Convert to radiansradians = torch.deg2rad(degrees)# Print the resultprint(radians)
Here is the output:
tensor([0.0000, 1.5708, 3.1416, 4.7124])
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 PyTorch on Codecademy
- Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
- Includes 6 Courses
- With Professional Certification
- Beginner Friendly.75 hours
- Learn how to use PyTorch to build, train, and test artificial neural networks in this course.
- Intermediate.3 hours