From 8f4823dbdf36de7c6643492abd31711f5bd48eb5 Mon Sep 17 00:00:00 2001 From: Lilla Csanaky Date: Sat, 24 Jan 2026 16:55:46 +0100 Subject: [PATCH 1/2] Create file and write content --- .../tensor-operations/terms/tan/tan.md | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 content/pytorch/concepts/tensor-operations/terms/tan/tan.md diff --git a/content/pytorch/concepts/tensor-operations/terms/tan/tan.md b/content/pytorch/concepts/tensor-operations/terms/tan/tan.md new file mode 100644 index 00000000000..761f5d76f2d --- /dev/null +++ b/content/pytorch/concepts/tensor-operations/terms/tan/tan.md @@ -0,0 +1,76 @@ +--- +Title: '.tan()' +Description: 'Returns the tangent of each element in the input tensor.' +Subjects: + - 'Computer Science' + - 'Machine Learning' +Tags: + - 'Deep Learning' + - 'PyTorch' + - 'Tensors' +CatalogContent: + - 'intro-to-py-torch-and-neural-networks' + - 'paths/machine-learning' +--- + +The **`.tan()`** function returns the tangent of each element in the input [tensor](https://www.codecademy.com/resources/docs/pytorch/tensors). It is part of PyTorch’s math operations used in deep learning and scientific computing. + +## Syntax + +```py +torch.tan(input, *, out=None) → Tensor +``` + +**Parameters:** + +- `input` (Tensor): Input tensor with one or more elements in radians. +- `out` (Tensor, optional): Optional tensor to store the output. + +**Return value:** + +A tensor containing the tangent of each input element, with the same shape as the input tensor. + +## Example 1: Using `.tan()` with a 1D tensor + +In this example, `.tan()` computes the tangent of a 1D tensor containing angles in radians: + +```py +import torch + +# Create a tensor with values in radians +input_tensor = torch.tensor([0, torch.pi / 4, torch.pi / 6]) + +# Compute the tangent +output_tensor = torch.tan(input_tensor) + +print(output_tensor) +``` + +The output of this code is: + +```shell +tensor([0.0000, 1.0000, 0.5774]) +``` + +## Example 2: Applying `.tan()` with a 2D tensor + +In this example, `.tan()` is applied to a 2D tensor of angles in radians: + +```py +import torch + +# Create a 2x2 tensor with elements with values in radians +matrix = torch.tensor([[0, torch.pi / 4], [torch.pi, torch.pi / 6]]) + +# Compute the tangent +result = torch.tan(matrix) + +print(result) +``` + +The output of this code is: + +```shell +tensor([[0.0000, 1.0000], + [0.0000, 0.5774]]) +``` From 8d8c13b292fb16fe0d4e437b85ce79d5801e6ffe Mon Sep 17 00:00:00 2001 From: Mamta Wardhani Date: Mon, 26 Jan 2026 15:50:43 +0530 Subject: [PATCH 2/2] Update documentation to use torch.tan() instead of .tan() --- .../concepts/tensor-operations/terms/tan/tan.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/content/pytorch/concepts/tensor-operations/terms/tan/tan.md b/content/pytorch/concepts/tensor-operations/terms/tan/tan.md index 761f5d76f2d..c36f3ec2b65 100644 --- a/content/pytorch/concepts/tensor-operations/terms/tan/tan.md +++ b/content/pytorch/concepts/tensor-operations/terms/tan/tan.md @@ -13,11 +13,11 @@ CatalogContent: - 'paths/machine-learning' --- -The **`.tan()`** function returns the tangent of each element in the input [tensor](https://www.codecademy.com/resources/docs/pytorch/tensors). It is part of PyTorch’s math operations used in deep learning and scientific computing. +The **`torch.tan()`** function returns the tangent of each element in the input [tensor](https://www.codecademy.com/resources/docs/pytorch/tensors). It is part of PyTorch’s math operations used in deep learning and scientific computing. ## Syntax -```py +```pseudo torch.tan(input, *, out=None) → Tensor ``` @@ -30,9 +30,9 @@ torch.tan(input, *, out=None) → Tensor A tensor containing the tangent of each input element, with the same shape as the input tensor. -## Example 1: Using `.tan()` with a 1D tensor +## Example 1: Using `torch.tan()` with a 1D tensor -In this example, `.tan()` computes the tangent of a 1D tensor containing angles in radians: +In this example, `torch.tan()` computes the tangent of a 1D tensor containing angles in radians: ```py import torch @@ -52,9 +52,9 @@ The output of this code is: tensor([0.0000, 1.0000, 0.5774]) ``` -## Example 2: Applying `.tan()` with a 2D tensor +## Example 2: Applying `torch.tan()` with a 2D tensor -In this example, `.tan()` is applied to a 2D tensor of angles in radians: +In this example, `torch.tan()` is applied to a 2D tensor of angles in radians: ```py import torch @@ -71,6 +71,6 @@ print(result) The output of this code is: ```shell -tensor([[0.0000, 1.0000], - [0.0000, 0.5774]]) +tensor([[0.0000e+00, 1.0000e+00], + [8.7423e-08, 5.7735e-01]]) ```