Python – PyTorch ceil() 方法
PyTorch torch.ceil()
方法返回一个新的张量,该张量具有输入元素的 ceil 值,这是大于或等于每个元素的最小整数。
Syntax: torch.ceil(inp, out=None)
Arguments
- inp: This is input tensor.
- out: The output tensor.
Return: It returns a Tensor.
让我们通过几个例子来看看这个概念:
示例 1:
示例 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]
在评论中写代码?请使用 ide.geeksforgeeks.org,生成链接并在此处分享链接。