Python – PyTorch fmod() 方法
PyTorch torch.fmod()
方法给出了除数的元素余数。除数可以是数字或张量。
Syntax: torch.fmod(input, div, out=None)
Arguments
- input: This is input tensor.
- div: This may be a number or a 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([5, 6, 7, 4])
print(a)
# Applying the fmod function and
# storing the result in 'out'
out = torch.fmod(a, 3)
print(out)
输出:
5
6
7
4
[torch.FloatTensor of size 4]
2
0
1
1
[torch.FloatTensor of size 4]
示例 2:
# Importing the PyTorch library
import torch
# A constant tensor of size n
a = torch.FloatTensor([5, 6, 7, 4])
b = torch.FloatTensor([2, 3, 4, 1])
print(a, b)
# Applying the fmod function and
# storing the result in 'out'
out = torch.fmod(a, b)
print(out)
输出:
5
6
7
4
[torch.FloatTensor of size 4]
2
3
4
1
[torch.FloatTensor of size 4]
1
0
3
0
[torch.FloatTensor of size 4]
在评论中写代码?请使用 ide.geeksforgeeks.org,生成链接并在此处分享链接。