jax.numpy.divmod#

jax.numpy.divmod(x1, x2, /)[source]#

Calculates the integer quotient and remainder of x1 by x2 element-wise

JAX implementation of numpy.divmod.

Parameters:
  • x1 (ArrayLike) – Input array, the dividend

  • x2 (ArrayLike) – Input array, the divisor

Returns:

A tuple of arrays (x1 // x2, x1 % x2).

Return type:

tuple[Array, Array]

See also

Examples

>>> x1 = jnp.array([10, 20, 30])
>>> x2 = jnp.array([3, 4, 7])
>>> jnp.divmod(x1, x2)
(Array([3, 5, 4], dtype=int32), Array([1, 0, 2], dtype=int32))
>>> x1 = jnp.array([-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5])
>>> x2 = 3
>>> jnp.divmod(x1, x2)
(Array([-2, -2, -1, -1, -1,  0,  0,  0,  1,  1,  1], dtype=int32),
 Array([1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2], dtype=int32))
>>> x1 = jnp.array([6, 6, 6], dtype=jnp.int32)
>>> x2 = jnp.array([1.9, 2.5, 3.1], dtype=jnp.float32)
>>> jnp.divmod(x1, x2)
(Array([3., 2., 1.], dtype=float32),
 Array([0.30000007, 1.        , 2.9       ], dtype=float32))