scipp.mod#

scipp.mod(dividend, divisor)#

Element-wise remainder.

Equivalent to:

dividend % divisor

In Scipp, the remainder is defined to complement scipp.floor_divide() meaning that:

a == floor(a / b) * b + a % b

This is the same definition as in numpy.mod and numpy.remainder.

Warning

This differs from the IEEE 754 remainder as implemented by math.remainder() and C’s remainder function and modulus operator, which complement round(a / b).

Parameters
Returns

Union[Variable, DataArray, Dataset] – Quotient.

Examples

>>> sc.mod(sc.arange('x', -3, 5), sc.scalar(3)).values
array([0, 1, 2, 0, 1, 2, 0, 1])
>>> sc.mod(sc.arange('x', -3, 5), sc.scalar(-3)).values
array([ 0, -2, -1,  0, -2, -1,  0, -2])

Or equivalently in operator notation

>>> (sc.arange('x', -3, 5) % sc.scalar(3)).values
array([0, 1, 2, 0, 1, 2, 0, 1])

Note

See the guide on computation for general concepts and broadcasting behavior.