From 2852cc136a873dd334485c3f149e1a1252dc111a Mon Sep 17 00:00:00 2001 From: Rishabh Ranjan Singh Date: Fri, 31 Oct 2025 14:25:14 +0530 Subject: [PATCH 1/3] docs: Add PyTorch tensor method .rad2deg() entry (#7852) --- .../terms/rad2deg/rad2deg.md | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 content/pytorch/concepts/tensor-operations/terms/rad2deg/rad2deg.md diff --git a/content/pytorch/concepts/tensor-operations/terms/rad2deg/rad2deg.md b/content/pytorch/concepts/tensor-operations/terms/rad2deg/rad2deg.md new file mode 100644 index 00000000000..52bd4b07d15 --- /dev/null +++ b/content/pytorch/concepts/tensor-operations/terms/rad2deg/rad2deg.md @@ -0,0 +1,68 @@ +--- +Title: '.rad2deg()' +Description: 'Converts the elements of a tensor from radians to degrees.' +Subjects: + - 'Computer Science' + - 'Data Science' +Tags: + - 'Functions' + - 'PyTorch' + - 'Tensor' + - 'Trigonometry' +CatalogContent: + - 'intro-to-py-torch-and-neural-networks' + - 'paths/data-science' +--- + +The **`.rad2deg()`** method in PyTorch converts the elements of a tensor from **radians to degrees**. This is useful for trigonometric and rotational operations when working with angular measurements. + +The operation is performed element-wise, meaning it applies the conversion formula ($$\text{degrees} = \text{radians} \times \frac{180}{\pi}$$) to every value in the tensor, returning a new tensor with the results. + +This method is available for tensors with floating-point data types such as `torch.float16`, `torch.float32`, or `torch.float64`. + +## Syntax + +```pseudo +torch.rad2deg(input) +``` + +**Parameters:** +* `input` (Tensor): A tensor containing angular values in radians. + +**Return value:** +Returns a tensor containing the degree equivalents of the original tensor's elements. The returned tensor has the same size and data type as the original input tensor. + +## Example + +This example demonstrates how to use `.rad2deg()` to convert common angular values ($\pi$ radians and $\frac{\pi}{2}$ radians) into degrees: + +```python +import torch +import math + +# Create a tensor with values in radians +radians_tensor = torch.tensor([ + math.pi / 2, + math.pi, + 0.0 +]) + +print("Original Tensor (Radians):") +print(radians_tensor) + +# Convert radians to degrees using torch.rad2deg() +degrees_tensor = torch.rad2deg(radians_tensor) + +print("\nConverted Tensor (Degrees):") +print(degrees_tensor) +``` + +The output of this code is: + +```shell +Original Tensor (Radians): +tensor([1.5708, 3.1416, 0.0000]) + +Converted Tensor (Degrees): +tensor([ 90.0000, 180.0000, 0.0000]) +``` \ No newline at end of file From 77a57cfbe987077974577a504c1f9ed41b1c40ee Mon Sep 17 00:00:00 2001 From: Daksha Deep Date: Fri, 31 Oct 2025 22:05:42 +0530 Subject: [PATCH 2/3] Update rad2deg.md --- .../tensor-operations/terms/rad2deg/rad2deg.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/content/pytorch/concepts/tensor-operations/terms/rad2deg/rad2deg.md b/content/pytorch/concepts/tensor-operations/terms/rad2deg/rad2deg.md index 52bd4b07d15..2f65f610b1a 100644 --- a/content/pytorch/concepts/tensor-operations/terms/rad2deg/rad2deg.md +++ b/content/pytorch/concepts/tensor-operations/terms/rad2deg/rad2deg.md @@ -14,9 +14,7 @@ CatalogContent: - 'paths/data-science' --- -The **`.rad2deg()`** method in PyTorch converts the elements of a tensor from **radians to degrees**. This is useful for trigonometric and rotational operations when working with angular measurements. - -The operation is performed element-wise, meaning it applies the conversion formula ($$\text{degrees} = \text{radians} \times \frac{180}{\pi}$$) to every value in the tensor, returning a new tensor with the results. +The **`.rad2deg()`** method in PyTorch converts the elements of a tensor from **radians to degrees**. This is useful for trigonometric and rotational operations when working with angular measurements. The operation is performed element-wise, meaning it applies the conversion formula ($$\text{degrees} = \text{radians} \times \frac{180}{\pi}$$) to every value in the tensor, returning a new tensor with the results. This method is available for tensors with floating-point data types such as `torch.float16`, `torch.float32`, or `torch.float64`. @@ -27,9 +25,11 @@ torch.rad2deg(input) ``` **Parameters:** -* `input` (Tensor): A tensor containing angular values in radians. + +- `input` (Tensor): A tensor containing angular values in radians. **Return value:** + Returns a tensor containing the degree equivalents of the original tensor's elements. The returned tensor has the same size and data type as the original input tensor. ## Example @@ -65,4 +65,4 @@ tensor([1.5708, 3.1416, 0.0000]) Converted Tensor (Degrees): tensor([ 90.0000, 180.0000, 0.0000]) -``` \ No newline at end of file +``` From c3d2300960edd8dcf9de16b3ec451264ec70bc0b Mon Sep 17 00:00:00 2001 From: Mamta Wardhani Date: Sat, 1 Nov 2025 16:51:43 +0530 Subject: [PATCH 3/3] minor content fixes --- .../tensor-operations/terms/rad2deg/rad2deg.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/content/pytorch/concepts/tensor-operations/terms/rad2deg/rad2deg.md b/content/pytorch/concepts/tensor-operations/terms/rad2deg/rad2deg.md index 2f65f610b1a..a665ea0d8db 100644 --- a/content/pytorch/concepts/tensor-operations/terms/rad2deg/rad2deg.md +++ b/content/pytorch/concepts/tensor-operations/terms/rad2deg/rad2deg.md @@ -14,9 +14,9 @@ CatalogContent: - 'paths/data-science' --- -The **`.rad2deg()`** method in PyTorch converts the elements of a tensor from **radians to degrees**. This is useful for trigonometric and rotational operations when working with angular measurements. The operation is performed element-wise, meaning it applies the conversion formula ($$\text{degrees} = \text{radians} \times \frac{180}{\pi}$$) to every value in the tensor, returning a new tensor with the results. +The **`.rad2deg()`** function in PyTorch converts the elements of a tensor from radians to degrees. This is useful for trigonometric and rotational operations when working with angular measurements. The operation is performed element-wise, meaning it applies the conversion formula ($$\text{degrees} = \text{radians} \times \frac{180}{\pi}$$) to every value in the tensor, returning a new tensor with the results. -This method is available for tensors with floating-point data types such as `torch.float16`, `torch.float32`, or `torch.float64`. +This function is available for tensors with floating-point data types such as `torch.float16`, `torch.float32`, or `torch.float64`. ## Syntax @@ -36,15 +36,15 @@ Returns a tensor containing the degree equivalents of the original tensor's elem This example demonstrates how to use `.rad2deg()` to convert common angular values ($\pi$ radians and $\frac{\pi}{2}$ radians) into degrees: -```python +```py import torch import math # Create a tensor with values in radians radians_tensor = torch.tensor([ - math.pi / 2, - math.pi, - 0.0 + math.pi / 2, + math.pi, + 0.0 ]) print("Original Tensor (Radians):")