Rate this Page

torch.remainder#

torch.remainder(input,other,*,out=None)Tensor#

ComputesPython’s modulus operationentrywise. The result has the same sign as the divisorother and its absolute valueis less than that ofother.

It may also be defined in terms oftorch.div() as

torch.remainder(a,b)==a-a.div(b,rounding_mode="floor")*b

Supportsbroadcasting to a common shape,type promotion, and integer and float inputs.

Note

Complex inputs are not supported. In some cases, it is not mathematicallypossible to satisfy the definition of a modulo operation with complex numbers.Seetorch.fmod() for how division by zero is handled.

See also

torch.fmod() which implements C++’sstd::fmod.This one is defined in terms of division rounding towards zero.

Parameters
  • input (Tensor orScalar) – the dividend

  • other (Tensor orScalar) – the divisor

Keyword Arguments

out (Tensor,optional) – the output tensor.

Example:

>>>torch.remainder(torch.tensor([-3.,-2,-1,1,2,3]),2)tensor([ 1.,  0.,  1.,  1.,  0.,  1.])>>>torch.remainder(torch.tensor([1,2,3,4,5]),-1.5)tensor([ -0.5000, -1.0000,  0.0000, -0.5000, -1.0000 ])