scipp.mod

scipp.mod(dividend, divisor)

Element-wise remainder.

This function corresponds to the modulus operator 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
  • dividend (VariableLike) – Dividend of the quotient.

  • divisor (VariableLike) – Divisor of the quotient.

Returns

Quotient.

Seealso

scipp.floor_divide(), scipp.divide()

Return type

VariableLike

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

Of equivalently in operator notation

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

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