You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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