PyTorch .exp()
Anonymous contributor
Published Jul 15, 2025
Contribute to Docs
In PyTorch, the .exp() function computes the exponential of each element in the input tensor. This is mathematically equivalent to applying the function $y_i = e^{x_i}$ element-wise, where e is Euler’s number (approximately 2.71828).
Syntax
torch.exp(input, *, out=None) → Tensor
Parameters:
input: The input tensor containing elements for which the exponential will be computed.out(optional): A tensor to store the output. If provided, the result is written to this tensor.
Return value:
Returns a new tensor where each element is the exponential of the corresponding element within the input tensor.
Example
In this example, we compute the element-wise exponential of a tensor using torch.exp():
import torchimport math# Define a tensorx = torch.tensor([0.0 , 1.0 , 2.0 , math.log(2.) ])# Compute the exponentialresult = torch.exp(x)print(result)
Here is the output:
tensor([1.0000 , 2.7183, 7.3891 , 2. ])
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
- Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
- Includes 6 Courses
- With Professional Certification
- Beginner Friendly.75 hours
- Learn how to use PyTorch to build, train, and test artificial neural networks in this course.
- Intermediate.3 hours