Elementwise exponential transforms
Transforming logits or other tensor values into positive exponential-scale quantities.
PyTorch · Function
Computes the elementwise exponential of a tensor. It can optionally write the result to a supplied output tensor.
torch.exp applies the exponential function element by element, producing a tensor whose values satisfy yᵢ = eˣᵢ. You can optionally provide an output tensor through the keyword-only out argument.
torch.exp(input, *, out=None) → Tensor| Name | Type | Description |
|---|---|---|
input | Tensor | The input tensor whose elements are exponentiated. |
out | Tensor, optional | Optional output tensor that receives the result. |
A new Tensor containing the elementwise exponential of input, or the supplied output tensor when out is used.
import math
import torch
x = torch.tensor([0.0, math.log(2.0)])
y = torch.exp(x)
print(y) # tensor([1., 2.])Computes the exponential independently for each element of the input tensor.
Transforming logits or other tensor values into positive exponential-scale quantities.
Constructing values such as powers of e from tensorized logarithms.
Writing results into an existing tensor buffer when an output destination is available.
torch.exp returns a new tensor containing the exponential of every element in the input. For each input value xᵢ, the corresponding output is eˣᵢ.
Follow-up: How can the result be written into a preallocated tensor? Pass that tensor with the keyword-only out argument.
The input parameter is a Tensor, and the function returns a Tensor. The operation is pointwise, so the output has the corresponding elementwise exponential values.
Follow-up: What optional argument is available? The documentation exposes out, an optional Tensor used as the output destination.
Its signature is torch.exp(input, *, out=None) → Tensor. The asterisk means out is keyword-only, while input is the tensor being transformed.
Follow-up: What mathematical relationship does the operation implement? Each output element follows yᵢ = eˣᵢ.
torch.exp_torch.Tensor.exptorch.special.exp2torch.special.expm1