PyTorch torch.log() method gives a new tensor having the natural logarithm of the elements of input tensor.
Syntax:
torch.log(input, out=None)Arguments
- input: This is input tensor.
- out: The output tensor.
Return: It returns a Tensor.
Let’s see this concept with the help of few examples:
Example 1:
Example 1:
# Importing the PyTorch library import torch # A constant tensor of size n a = torch.FloatTensor([5, 6, 7, 4]) print(a) # Applying the log function and # storing the result in 'out' out = torch.log(a) print(out) |
chevron_right
filter_none
Output:
5 6 7 4 [torch.FloatTensor of size 4] 1.6094 1.7918 1.9459 1.3863 [torch.FloatTensor of size 4]
Example 2:
# Importing the PyTorch library import torch # A constant tensor of size n a = torch.FloatTensor([1.45, 2.3, 10]) print(a) # Applying the log function and # storing the result in 'out' out = torch.log(a) print(out) |
chevron_right
filter_none
Output:
1.4500 2.3000 10.0000 [torch.FloatTensor of size 3] 0.3716 0.8329 2.3026 [torch.FloatTensor of size 3]
Recommended Posts:
- Python - PyTorch abs() method
- Python Pytorch eye() method
- Python Pytorch ones() method
- Python | PyTorch cos() method
- Python | PyTorch sin() method
- Python | PyTorch tan() method
- Python - PyTorch exp() method
- Python - PyTorch div() method
- Python - PyTorch add() method
- Python Pytorch range() method
- Python - PyTorch is_storage() method
- Python - PyTorch numel() method
- Python - PyTorch fmod() method
- Python - PyTorch floor() method
- Python - PyTorch frac() method
- Python | PyTorch atan() method
- Python - PyTorch is_storage() method
- Python | PyTorch asin() method
- Python - PyTorch is_tensor() method
- Python | PyTorch acos() method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

