Skip to content

Commit d180acc

Browse files
[Term Entry] PyTorch log10() (#7613)
* init: creation of log10 and init metadata * docs: syntax and example * fix: tensor reference link * minor wording tweaks * fix: minor wording tweaks ---------
1 parent 6c3becc commit d180acc

File tree

1 file changed

+55
-0
lines changed
  • content/pytorch/concepts/tensor-operations/terms/log10

1 file changed

+55
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
---
2+
Title: '.log10()'
3+
Description: 'Returns a tensor containing the base-10 logarithm of each element in the input tensor.'
4+
Subjects:
5+
- 'Computer Science'
6+
- 'Machine Learning'
7+
Tags:
8+
- 'Functions'
9+
- 'Machine Learning'
10+
- 'Python'
11+
- 'Tensor'
12+
CatalogContent:
13+
- 'intro-to-py-torch-and-neural-networks'
14+
- 'paths/computer-science'
15+
---
16+
17+
In PyTorch, the **`.log10()`** function computes the base-10 logarithm of each element in the input [tensor](https://www.codecademy.com/resources/docs/pytorch/tensors). Mathematically, this is equivalent to applying the function $y_i = \log_{10}(x_i)$ element-wise, where $log_{10}$ is the base-10 logarithm.
18+
19+
## Syntax
20+
21+
```pseudo
22+
torch.log10(input, *, out=None) → Tensor
23+
```
24+
25+
**Parameters:**
26+
27+
- `input`: The input tensor containing elements for which the logarithm will be computed.
28+
- `out` (optional): A tensor to store the output. If provided, the result is written to this tensor. Must have the same shape as `input`.
29+
30+
**Return value:**
31+
32+
Returns a new tensor where each element is the base-10 logarithm of the corresponding element in `input`.
33+
34+
## Example
35+
36+
The following example shows how to compute the element-wise logarithm base 10 of a tensor using `torch.log10()`:
37+
38+
```py
39+
import torch
40+
import math
41+
42+
# Define a tensor
43+
x = torch.tensor([5.0 , 6.0 , 7.0 , math.log(2.) ])
44+
45+
# Compute the logarithm base 10
46+
result = torch.log10(x)
47+
48+
print(result)
49+
```
50+
51+
Here is the output:
52+
53+
```shell
54+
tensor([ 0.6990, 0.7782, 0.8451, -0.1592])
55+
```

0 commit comments

Comments
 (0)