Skip to content

Commit 10c40f2

Browse files
authored
Merge branch 'main' into feat/add-numpy-byteswap-term
2 parents 5434094 + 2f2ad45 commit 10c40f2

File tree

1 file changed

+53
-0
lines changed
  • content/pytorch/concepts/tensor-operations/terms/logaddexp2

1 file changed

+53
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
---
2+
Title: '.logaddexp2()'
3+
Description: 'Computes the logarithm of the sum of exponentials of two tensors in base 2.'
4+
Subjects:
5+
- 'Code Foundations'
6+
- 'Computer Science'
7+
Tags:
8+
- 'PyTorch'
9+
- 'Tensor'
10+
CatalogContent:
11+
- 'learn-pytorch'
12+
- 'intro-to-py-torch-and-neural-networks'
13+
---
14+
15+
In PyTorch, the **`.logaddexp2()`** function computes the element-wise $$log_2(2^x + 2^y)$$ of the given [tensor](https://www.codecademy.com/resources/docs/pytorch/tensors) inputs.
16+
17+
## Syntax
18+
19+
```pseudo
20+
torch.logaddexp2(input,other,*,out=None)
21+
```
22+
23+
**Parameters:**
24+
25+
- `input`: The first input tensor
26+
- `other`: The second input tensor
27+
- `out`: The output tensor to store the result. Default is `None`.
28+
29+
**Return value:**
30+
31+
The `torch.logaddexp2()` method returns a tensor containing the element-wise logarithm (base 2) of the sum of exponentials of the corresponding elements in the input tensors.
32+
33+
## Example
34+
35+
In this example, `torch.logaddexp2()` is used to combine two tensors into a single tensor by computing their log-sum in base 2:
36+
37+
```py
38+
import torch
39+
40+
# Example tensors
41+
x = torch.tensor([1.0, 2.0, 3.0])
42+
y = torch.tensor([0.5, 2.5, 1.5])
43+
44+
# Compute logaddexp2
45+
result = torch.logaddexp2(x, y)
46+
print(result)
47+
```
48+
49+
This code will produce the following output:
50+
51+
```shell
52+
tensor([1.7716, 3.2716, 3.4368])
53+
```

0 commit comments

Comments
 (0)