Skip to content

Attempt to create an exp2 entry fot pytorch #7480

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Aug 20, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions content/pytorch/concepts/tensor-operations/terms/exp2/exp2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
---
Title: '.exp2()'
Description: 'Returns a new tensor with the base-2 exponential of each element in the input tensor.'
Subjects:
- 'Computer Science'
- 'Machine Learning'
Tags:
- 'Deep Learning'
- 'Functions'
- 'Tensor'
CatalogContent:
- 'intro-to-py-torch-and-neural-networks'
- 'paths/computer-science'
---

The **`.exp2()`** function in PyTorch computes the base-2 exponential of each element in the input [tensor](https://www.codecademy.com/resources/docs/pytorch/tensors). This function is useful for various mathematical operations and can be applied to tensors of any shape. The result is a new tensor with the same shape as the input, containing the base-2 exponentials of the input values.

## Syntax

```pseudo
# Function syntax:
result = torch.exp2(input, *, out=None)

# Tensor method syntax:
result = tensor.exp2()
```

This function is an alias for:

```pseudo
torch.special.exp2(input, *, out=None)
```

**Parameters:**

- input (Tensor): The input tensor
- out (Tensor, optional): The output tensor to store the result

**Return value:**

The `.exp2()` function returns a tensor with the base-2 exponentials of the input tensor, same shape as the input.

## Example

Here's an example of how to use the `.exp2()` function in PyTorch:

```py
import torch

# Create a tensor
x = torch.tensor([1.0, 2.0, 3.0])

# Compute the base-2 exponential
y = x.exp2()

print(y)
```

The output will be:

```shell
tensor([2., 4., 8.])
```

In this example, the `.exp2()` function is applied to the tensor `x`, and the result is stored in the tensor `y`. The output will be a tensor containing the base-2 exponentials of the elements in `x`.