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

Computes the element-wise remainder of division.

The dividend and divisor may contain both for integer and floating point numbers. The remainder has the same sign as the divisor other.

When other is a tensor, the shapes of input and other must be broadcastable.

  • input (Tensor) – the dividend

  • other (Tensor or float) – the divisor that may be either a number or a Tensor of the same shape as the dividend

Keyword Arguments

out (Tensor, optional) – the output tensor.


>>> 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([ 1.0000,  0.5000,  0.0000,  1.0000,  0.5000])

See also

torch.fmod(), which computes the element-wise remainder of division equivalently to the C library function fmod().


Access comprehensive developer documentation for PyTorch

View Docs


Get in-depth tutorials for beginners and advanced developers

View Tutorials


Find development resources and get your questions answered

View Resources