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]]) +```