Buy Me a Coffee☕
*Memos:
fmod() can do the modulo(mod) calculation of C ’s std::fmod with two of the 0D or more D tensors of zero or more elements or the 0D or more D tensor of zero or more elements and a scalar, getting the 0D or more D tensor of zero or more elements as shown below:
*Memos:
import torch tensor1 = torch.tensor([9, 7, 6]) tensor2 = torch.tensor([[4, -4, 3], [-2, 5, -5]]) torch.fmod(input=tensor1, other=tensor2) tensor1.fmod(other=tensor2) # tensor([[1, 3, 0], [1, 2, 1]]) torch.fmod(input=tensor1, other=4) # tensor([1, 3, 2]) tensor1 = torch.tensor([-9, -7, -6]) tensor2 = torch.tensor([[4, -4, 3], [-2, 5, -5]]) torch.fmod(input=tensor1, other=tensor2) # tensor([[-1, -3, 0], [-1, -2, -1]]) torch.fmod(input=tensor1, other=4) # tensor([-1, -3, -2]) tensor1 = torch.tensor([9.75, 7.08, 6.26]) tensor2 = torch.tensor([[4.26, -4.54, 3.37], [-2.16, 5.43, -5.98]]) torch.fmod(input=tensor1, other=tensor2) # tensor([[1.2300, 2.5400, 2.8900], [1.1100, 1.6500, 0.2800]]) torch.fmod(input=tensor1, other=4.26) # tensor([1.2300, 2.8200, 2.0000])
The above is the detailed content of fmod in PyTorch. For more information, please follow other related articles on the PHP Chinese website!