📜  Python – PyTorch ceil() 方法

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

Python – PyTorch ceil() 方法

PyTorch torch.ceil()方法返回一个新的张量,该张量具有输入元素的 ceil 值,这是大于或等于每个元素的最小整数。

让我们通过几个例子来看看这个概念:
示例 1:
# Importing the PyTorch library 
import torch 
    
# A constant tensor of size n
a = torch.FloatTensor([1.3, -5.6, 7.9, 10.1])
print(a)
  
# Applying the ceil function and 
# storing the result in 'out'
out = torch.ceil(a)
print(out)

输出:

1.3000
 -5.6000
  7.9000
 10.1000
[torch.FloatTensor of size 4]
  2
 -5
  8
 11
[torch.FloatTensor of size 4]

示例 2:

# Importing the PyTorch library 
import torch 
    
# A constant tensor of size n
a = torch.FloatTensor([1.00001, -5.699, 7.100001, 10.0001])
print(a)
  
# Applying the ceil function and 
# storing the result in 'out'
out = torch.ceil(a)
print(out) 

输出:

1.0000
 -5.6990
  7.1000
 10.0001
[torch.FloatTensor of size 4]
  2
 -5
  8
 11
[torch.FloatTensor of size 4]