divmod

Contents

divmod#

class brainunit.math.divmod(x, y, **kwargs)#

Return element-wise quotient and remainder simultaneously.

Equivalent to (x // y, x % y), but faster because it avoids redundant work. When x and y share a dimension, the operands are aligned to x.unit first (floor is not scale-linear): the quotient is dimensionless and the remainder carries x.unit. For mixed dimensions, both operands are folded to magnitude-1 (base) units so the result does not depend on the unit representation; the quotient then carries the base x.unit / y.unit and the remainder the base unit of x.

Parameters:
  • x (Union[saiunit.Quantity, Array, ndarray, number, bool]) – Dividend array.

  • y (Union[saiunit.Quantity, Array, ndarray, number, bool]) – Divisor array. If x.shape != y.shape, they must be broadcastable to a common shape.

Return type:

Tuple[Union[saiunit.Quantity, Array, ndarray, number, bool], Union[saiunit.Quantity, Array, ndarray, number, bool]]

Returns:

  • out1 (ndarray or Quantity) – Element-wise quotient resulting from floor division.

  • out2 (ndarray or Quantity) – Element-wise remainder from floor division, with the dimension of x.

Examples

>>> import saiunit as u
>>> a = u.math.array([7.0, 9.0]) * u.meter
>>> b = u.math.array([2.0, 4.0]) * u.second
>>> quotient, remainder = u.math.divmod(a, b)