PyTorch .log10()

alessandrocapialbi's avatar
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.

  • 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

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 as input.

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 torch
import math
# Define a tensor
x = torch.tensor([5.0 , 6.0 , 7.0 , math.log(2.) ])
# Compute the logarithm base 10
result = torch.log10(x)
print(result)

Here is the output:

tensor([ 0.6990, 0.7782, 0.8451, -0.1592])

All contributors

Contribute to 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