Skip to content

Commit 8796f48

Browse files
authored
Attempt to create an exp2 entry fot pytorch (#7480)
* Attempt to create n exp2 entry fot pytorch * Update exp2.md * minor updates * Update content/pytorch/concepts/tensor-operations/terms/exp2/exp2.md * Update content/pytorch/concepts/tensor-operations/terms/exp2/exp2.md * Update content/pytorch/concepts/tensor-operations/terms/exp2/exp2.md ---------
1 parent 50f338b commit 8796f48

File tree

1 file changed

+65
-0
lines changed
  • content/pytorch/concepts/tensor-operations/terms/exp2

1 file changed

+65
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
---
2+
Title: '.exp2()'
3+
Description: 'Returns a new tensor with the base-2 exponential of each element in the input tensor.'
4+
Subjects:
5+
- 'Computer Science'
6+
- 'Machine Learning'
7+
Tags:
8+
- 'Deep Learning'
9+
- 'Functions'
10+
- 'Tensor'
11+
CatalogContent:
12+
- 'intro-to-py-torch-and-neural-networks'
13+
- 'paths/computer-science'
14+
---
15+
16+
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.
17+
18+
## Syntax
19+
20+
```pseudo
21+
# Function syntax:
22+
result = torch.exp2(input, *, out=None)
23+
24+
# Tensor method syntax:
25+
result = tensor.exp2()
26+
```
27+
28+
This function is an alias for:
29+
30+
```pseudo
31+
torch.special.exp2(input, *, out=None)
32+
```
33+
34+
**Parameters:**
35+
36+
- input (Tensor): The input tensor
37+
- out (Tensor, optional): The output tensor to store the result
38+
39+
**Return value:**
40+
41+
The `.exp2()` function returns a tensor with the base-2 exponentials of the input tensor, same shape as the input.
42+
43+
## Example
44+
45+
Here's an example of how to use the `.exp2()` function in PyTorch:
46+
47+
```py
48+
import torch
49+
50+
# Create a tensor
51+
x = torch.tensor([1.0, 2.0, 3.0])
52+
53+
# Compute the base-2 exponential
54+
y = x.exp2()
55+
56+
print(y)
57+
```
58+
59+
The output will be:
60+
61+
```shell
62+
tensor([2., 4., 8.])
63+
```
64+
65+
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`.

0 commit comments

Comments
 (0)