PyTorch torch.fmod() method gives the element-wise remainder of division by divisor. The divisor may be a number or a Tensor.
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.
Let’s see this concept with the help of few examples:
Example 1:
Example 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) |
chevron_right
filter_none
Output:
5 6 7 4 [torch.FloatTensor of size 4] 2 0 1 1 [torch.FloatTensor of size 4]
Example 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) |
chevron_right
filter_none
Output:
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]
Recommended Posts:
- Python | PyTorch tan() method
- Python | PyTorch cos() method
- Python Pytorch ones() method
- Python - PyTorch exp() method
- Python - PyTorch div() method
- Python - PyTorch add() method
- Python - PyTorch abs() method
- Python | PyTorch sin() method
- Python - PyTorch log() method
- Python Pytorch eye() method
- Python | PyTorch atan() method
- Python | PyTorch acos() method
- Python | PyTorch asin() method
- Python Pytorch full() method
- Python - PyTorch clamp() method
- Python - PyTorch ceil() method
- Python - PyTorch floor() method
- Python - PyTorch is_storage() method
- Python - PyTorch is_tensor() method
- Python Pytorch arange() method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

