log2() and log10() in PyTorch

Buy Me a Coffee☕

*My post explains log() and log1p().

log2() can get the 0D or more D tensor of the zero or more logarithms based on 2 from the 0D or more D tensor of zero or more elements as shown below:

*Memos:

log2() can be used with torch or …


This content originally appeared on DEV Community and was authored by Super Kai (Kazuya Ito)

Buy Me a Coffee

*My post explains log() and log1p().

log2() can get the 0D or more D tensor of the zero or more logarithms based on 2 from the 0D or more D tensor of zero or more elements as shown below:

*Memos:

  • log2() can be used with torch or a tensor.
  • The 1st argument(input) with torch or using a tensor(Required-Type:tensor of int, float, complex or bool).
  • There is out argument with torch(Optional-Type:tensor): *Memos:
    • out= must be used.
    • My post explains out argument.
  • *A float tensor is returned unless an input tensor is complex tensor.
  • 's formula is y = log2(x).
  • 's graph in Desmos: Image description
import torch

my_tensor = torch.tensor([-0.1, 0.0, 0.1, 0.9, 1.0, 1.1, 2.0, 100.0])

torch.log2(input=my_tensor)
my_tensor.log2()
# tensor([nan, -inf, -3.3219, -0.1520, 0.0000, 0.1375, 1.0000, 6.6439])

my_tensor = torch.tensor([[-0.1, 0.0, 0.1, 0.9],
                          [1.0, 1.1, 2.0, 100.0]])
torch.log2(input=my_tensor)
# tensor([[nan, -inf, -3.3219, -0.1520],
#         [0.0000, 0.1375, 1.0000, 6.6439]])

my_tensor = torch.tensor([[[-0.1, 0.0], [0.1, 0.9]],
                          [[1.0, 1.1], [2.0, 100.0]]])
torch.log2(input=my_tensor)
# tensor([[[nan, -inf], [-3.3219, -0.1520]],
#         [[0.0000, 0.1375], [1.0000, 6.6439]]])

my_tensor = torch.tensor([[[-0.1+0.j, 0.0+0.j], [0.1+0.j, 0.9+0.j]],
                          [[1.0+0.j, 1.1+0.j], [2.0+0.j, 100.0+0.j]]])
torch.log2(input=my_tensor)
# tensor([[[-3.3219+4.5324j, -inf+0.0000j],
#          [-3.3219+0.0000j, -0.1520+0.0000j]],
#         [[0.0000+0.0000j, 0.1375+0.0000j],
#          [1.0000+0.0000j, 6.6439+0.0000j]]])

my_tensor = torch.tensor([[[-1, 0], [1, 2]],
                          [[5, 8], [10, 100]]])
torch.log2(input=my_tensor)
# tensor([[[nan, -inf], [0.0000, 1.0000]],
#         [[2.3219, 3.0000], [3.3219, 6.6439]]])

my_tensor = torch.tensor([[[True, False], [True, False]],
                          [[False, True], [False, True]]])
torch.log2(input=my_tensor)
# tensor([[[0., -inf], [0., -inf]],
#         [[-inf, 0.], [-inf, 0.]]])

log10() can get the 0D or more D tensor of the zero or more logarithms based on 2 from the 0D or more D tensor of zero or more elements as shown below:

*Memos:

  • log10() can be used with torch or a tensor.
  • The 1st argument(input) with torch or using a tensor(Required-Type:tensor of int, float, complex or bool).
  • There is out argument with torch(Optional-Type:tensor): *Memos:
    • out= must be used.
    • My post explains out argument.
  • *A float tensor is returned unless an input tensor is complex tensor.
  • 's formula is y = log10(x).
  • 's graph in Desmos: Image description
import torch

my_tensor = torch.tensor([-0.1, 0.0, 0.1, 0.9, 1.0, 1.1, 10.0, 100.0])

torch.log10(input=my_tensor)
my_tensor.log10()
# tensor([nan, -inf, -1.0000, -0.0458, 0.0000, 0.0414, 1.0000, 2.0000])

my_tensor = torch.tensor([[-0.1, 0.0, 0.1, 0.9],
                          [1.0, 1.1, 10.0, 100.0]])
torch.log10(input=my_tensor)
# tensor([[nan, -inf, -1.0000, -0.0458],
#         [0.0000, 0.0414, 1.0000, 2.0000]])

my_tensor = torch.tensor([[[-0.1, 0.0], [0.1, 0.9]],
                          [[1.0, 1.1], [10.0, 100.0]]])
torch.log10(input=my_tensor)
# tensor([[[nan, -inf],
#          [-1.0000, -0.0458]],
#         [[ 0.0000, 0.0414],
#          [ 1.0000, 2.0000]]])

my_tensor = torch.tensor([[[-0.1+0.j, 0.0+0.j], [0.1+0.j, 0.9+0.j]],
                          [[1.0+0.j, 1.1+0.j], [10.0+0.j, 100.0+0.j]]])
torch.log10(input=my_tensor)
# tensor([[[-1.0000+1.3644j, -inf+0.0000j],
#          [-1.0000+0.0000j, -0.0458+0.0000j]],
#         [[0.0000+0.0000j, 0.0414+0.0000j],
#          [1.0000+0.0000j, 2.0000+0.0000j]]])

my_tensor = torch.tensor([[[-1, 0], [1, 2]],
                          [[5, 8], [10, 100]]])
torch.log10(input=my_tensor)
# tensor([[[nan, -inf], [0.0000, 0.3010]],
#         [[0.6990, 0.9031], [1.0000, 2.0000]]])

my_tensor = torch.tensor([[[True, False], [True, False]],
                          [[False, True], [False, True]]])
torch.log10(input=my_tensor)
# tensor([[[0., -inf], [0., -inf]],
#         [[-inf, 0.], [-inf, 0.]]])


This content originally appeared on DEV Community and was authored by Super Kai (Kazuya Ito)


Print Share Comment Cite Upload Translate Updates
APA

Super Kai (Kazuya Ito) | Sciencx (2024-09-02T17:32:09+00:00) log2() and log10() in PyTorch. Retrieved from https://www.scien.cx/2024/09/02/log2-and-log10-in-pytorch/

MLA
" » log2() and log10() in PyTorch." Super Kai (Kazuya Ito) | Sciencx - Monday September 2, 2024, https://www.scien.cx/2024/09/02/log2-and-log10-in-pytorch/
HARVARD
Super Kai (Kazuya Ito) | Sciencx Monday September 2, 2024 » log2() and log10() in PyTorch., viewed ,<https://www.scien.cx/2024/09/02/log2-and-log10-in-pytorch/>
VANCOUVER
Super Kai (Kazuya Ito) | Sciencx - » log2() and log10() in PyTorch. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/09/02/log2-and-log10-in-pytorch/
CHICAGO
" » log2() and log10() in PyTorch." Super Kai (Kazuya Ito) | Sciencx - Accessed . https://www.scien.cx/2024/09/02/log2-and-log10-in-pytorch/
IEEE
" » log2() and log10() in PyTorch." Super Kai (Kazuya Ito) | Sciencx [Online]. Available: https://www.scien.cx/2024/09/02/log2-and-log10-in-pytorch/. [Accessed: ]
rf:citation
» log2() and log10() in PyTorch | Super Kai (Kazuya Ito) | Sciencx | https://www.scien.cx/2024/09/02/log2-and-log10-in-pytorch/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.