PyTorch .logaddexp2()

Anonymous contributor's avatar
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 tensor
  • other: The second input tensor
  • out: The output tensor to store the result. Default is None.

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 tensors
x = torch.tensor([1.0, 2.0, 3.0])
y = torch.tensor([0.5, 2.5, 1.5])
# Compute logaddexp2
result = torch.logaddexp2(x, y)
print(result)

This code will produce the following output:

tensor([1.7716, 3.2716, 3.4368])

All contributors

Contribute to Docs

Learn PyTorch on Codecademy