Thursday, September 4, 2025
HomeLanguagesPython – PyTorch fmod() method

Python – PyTorch fmod() method

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:




# 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)


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)


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]
Last Updated :
26 May, 2020
Like Article
Save Article

<!–

–>

Similar Reads
Related Tutorials
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32264 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6629 POSTS0 COMMENTS
Nicole Veronica
11799 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11859 POSTS0 COMMENTS
Shaida Kate Naidoo
6749 POSTS0 COMMENTS
Ted Musemwa
7025 POSTS0 COMMENTS
Thapelo Manthata
6698 POSTS0 COMMENTS
Umr Jansen
6717 POSTS0 COMMENTS