*Memos:
- My post explains log2() and log10().
- My post explains exp() and exp2().
- My post explains expm1() and sigmoid().
log() can get the 0D or more D tensor of the zero or more elements by ln(x)
which is the natural logarithm based on e
, from the 0D or more D tensor of zero or more elements as shown below:
*Memos:
-
log()
can be used with torch or a tensor. - The 1st argument(
input
) withtorch
or using a tensor(Required-Type:tensor
ofint
,float
,complex
orbool
). - There is
out
argument withtorch
(Optional-Default:None
-Type:tensor
): *Memos:-
out=
must be used. - My post explains
out
argument.
-
- *A
float
tensor is returned unless an input tensor iscomplex
tensor. - The formula is y = ln(x) or y = loge(x).
- The graph in Desmos:
import torch my_tensor = torch.tensor([-0.1, 0.0, 0.1, 0.9, 1.0, 1.1, torch.e, 100.0]) torch.log(input=my_tensor) my_tensor.log() # tensor([nan, -inf, -2.3026, -0.1054, 0.0000, 0.0953, 1.0000, 4.6052]) my_tensor = torch.tensor([[-0.1, 0.0, 0.1, 0.9], [1.0, 1.1, torch.e, 100.0]]) torch.log(input=my_tensor) # tensor([[nan, -inf, -2.3026, -0.1054], # [0.0000, 0.0953, 1.0000, 4.6052]]) my_tensor = torch.tensor([[[-0.1, 0.0], [0.1, 0.9]], [[1.0, 1.1], [torch.e, 100.0]]]) torch.log(input=my_tensor) # tensor([[[nan, -inf], [-2.3026, -0.1054]], # [[0.0000, 0.0953], [1.0000, 4.6052]]]) 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], [torch.e+0.j, 100.0+0.j]]]) torch.log(input=my_tensor) # tensor([[[-2.3026+3.1416j, -inf+0.0000j], # [-2.3026+0.0000j, -0.1054+0.0000j]], # [[0.0000+0.0000j, 0.0953+0.0000j], # [1.0000+0.0000j, 4.6052+0.0000j]]]) my_tensor = torch.tensor([[[-1, 0], [1, 2]], [[5, 8], [10, 100]]]) torch.log(input=my_tensor) # tensor([[[nan, -inf], [0.0000, 0.6931]], # [[1.6094, 2.0794], [2.3026, 4.6052]]]) my_tensor = torch.tensor([[[True, False], [True, False]], [[False, True], [False, True]]]) torch.log(input=my_tensor) # tensor([[[0., -inf], [0., -inf]], # [[-inf, 0.], [-inf, 0.]]])
log1p() can get the 0D or more D tensor of the zero or more elements by ln(x + 1)
which is the natural logarithm based on e
, from the 0D or more D tensor of zero or more elements as shown below:
*Memos:
-
log1p()
can be used with torch or a tensor. - The 1st argument(
input
) withtorch
or using a tensor(Required-Type:tensor
ofint
,float
,complex
orbool
). - There is
out
argument withtorch
(Optional-Default:None
-Type:tensor
): *Memos:-
out=
must be used. - My post explains
out
argument.
-
- *A
float
tensor is returned unless an input tensor iscomplex
tensor. - The formula is y = ln(x + 1) or y = loge(x + 1).
- The graph in Desmos:
import torch my_tensor = torch.tensor([-1.1, -1.0, -0.9, -0.1, 0.0, 0.1, torch.e, 10.0]) torch.log1p(input=my_tensor) my_tensor.log1p() # tensor([nan, -inf, -2.3026, -0.1054, 0.0000, 0.0953, 1.3133, 2.3979]) my_tensor = torch.tensor([[-1.1, -1.0, -0.9, -0.1], [0.0, 0.1, torch.e, 10.0]]) torch.log1p(input=my_tensor) # tensor([[nan, -inf, -2.3026, -0.1054], # [0.0000, 0.0953, 1.3133, 2.3979]]) my_tensor = torch.tensor([[[-1.1, -1.0], [-0.9, -0.1]], [[0.0, 0.1], [torch.e, 10.0]]]) torch.log1p(input=my_tensor) # tensor([[[nan, -inf], [-2.3026, -0.1054]], # [[0.0000, 0.0953], [1.3133, 2.3979]]]) my_tensor = torch.tensor([[[-1.1+0.j, -1.0+0.j], [-0.9+0.j, -0.1+0.j]], [[0.0+0.j, 0.1+0.j], [torch.e+0.j, 10.0+0.j]]]) torch.log1p(input=my_tensor) # tensor([[[-2.3026+3.1416j, -inf+0.0000j], # [-2.3026+0.0000j, -0.1054+0.0000j]], # [[0.0000+0.0000j, 0.0953+0.0000j], # [1.3133+0.0000j, 2.3979+0.0000j]]]) my_tensor = torch.tensor([[[-1, 0], [1, 2]], [[5, 8], [10, 100]]]) my_tensor = torch.tensor([[[-2, -1], [0, 1]], [[2, 5], [8, 10]]]) torch.log1p(input=my_tensor) # tensor([[[nan, -inf], [0.0000, 0.6931]], # [[1.0986, 1.7918], [2.1972, 2.3979]]]) my_tensor = torch.tensor([[[True, False], [True, False]], [[False, True], [False, True]]]) torch.log1p(input=my_tensor) # tensor([[[0.6931, 0.0000], [0.6931, 0.0000]], # [[0.0000, 0.6931], [0.0000, 0.6931]]])
Top comments (0)