Python – PyTorch floor() 方法
PyTorch torch.floor()
方法返回一个新的张量,它是输入元素的下限,小于或等于每个元素的最大整数。
Syntax: torch.floor(input, out=None)
Arguments
- input: 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.5, 4.2, 6.7, 3.9])
print(a)
# Applying the floor function and
# storing the result in 'out'
out = torch.floor(a)
print(out)
输出:
1.5000
4.2000
6.7000
3.9000
[torch.FloatTensor of size 4]
1
4
6
3
[torch.FloatTensor of size 4]
示例 2:
# Importing the PyTorch library
import torch
# A constant tensor of size n
a = torch.FloatTensor([1.59, 4.5999, 6.78, 3.99999])
print(a)
# Applying the floor function and
# storing the result in 'out'
out = torch.floor(a)
print(out)
输出:
1.5900
4.5999
6.7800
4.0000
[torch.FloatTensor of size 4]
1
4
6
3
[torch.FloatTensor of size 4]
在评论中写代码?请使用 ide.geeksforgeeks.org,生成链接并在此处分享链接。