PyTorch .log10()
Published Oct 29, 2025
Contribute to Docs
In PyTorch, the .log10() function computes the base-10 logarithm of each element in the input tensor. Mathematically, this is equivalent to applying the function $y_i = \log_{10}(x_i)$ element-wise, where $log_{10}$ is the base-10 logarithm.
Syntax
torch.log10(input, *, out=None) → Tensor
Parameters:
input: The input tensor containing elements for which the logarithm will be computed.out(optional): A tensor to store the output. If provided, the result is written to this tensor. Must have the same shape asinput.
Return value:
Returns a new tensor where each element is the base-10 logarithm of the corresponding element in input.
Example
The following example shows how to compute the element-wise logarithm base 10 of a tensor using torch.log10():
import torchimport math# Define a tensorx = torch.tensor([5.0 , 6.0 , 7.0 , math.log(2.) ])# Compute the logarithm base 10result = torch.log10(x)print(result)
Here is the output:
tensor([ 0.6990, 0.7782, 0.8451, -0.1592])
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