PyTorch .logaddexp2()
Anonymous contributor
Published Oct 30, 2025
Contribute to Docs
In PyTorch, the .logaddexp2() function computes the element-wise $$log_2(2^x + 2^y)$$ of the given tensor inputs.
Syntax
torch.logaddexp2(input,other,*,out=None)
Parameters:
input: The first input tensorother: The second input tensorout: The output tensor to store the result. Default isNone.
Return value:
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.
Example
In this example, torch.logaddexp2() is used to combine two tensors into a single tensor by computing their log-sum in base 2:
import torch# Example tensorsx = torch.tensor([1.0, 2.0, 3.0])y = torch.tensor([0.5, 2.5, 1.5])# Compute logaddexp2result = torch.logaddexp2(x, y)print(result)
This code will produce the following output:
tensor([1.7716, 3.2716, 3.4368])
All contributors
- Anonymous contributor
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn PyTorch on Codecademy
- Learn how to use PyTorch to build, train, and test artificial neural networks in this course.
- Intermediate.3 hours