📜  Python – PyTorch log() 方法

📅  最后修改于: 2022-05-13 01:54:58.799000             🧑  作者: Mango

Python – PyTorch log() 方法

PyTorch torch.log()方法给出了一个新张量,该张量具有输入张量元素的自然对数。

让我们通过几个例子来看看这个概念:
示例 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)

输出:

5
 6
 7
 4
[torch.FloatTensor of size 4]

 1.6094
 1.7918
 1.9459
 1.3863
[torch.FloatTensor of size 4]

示例 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)

输出:

1.4500
  2.3000
 10.0000
[torch.FloatTensor of size 3]

 0.3716
 0.8329
 2.3026
[torch.FloatTensor of size 3]