dpnp.divmod
- dpnp.divmod(x1, x2, out1=None, out2=None, /, *, out=(None, None), where=True, order='K', dtype=None, subok=True, **kwargs)
Calculates the quotient and the remainder for each element \(x1_i\) of the input array x1 with the respective element \(x2_i\) of the input array x2.
For full documentation refer to
numpy.divmod.- Parameters:
x1 ({dpnp.ndarray, usm_ndarray}) -- Dividend input array, expected to have a real-valued floating-point data type.
x2 ({dpnp.ndarray, usm_ndarray}) -- Divisor input array, expected to have a real-valued floating-point data type.
out1 ({None, dpnp.ndarray, usm_ndarray}, optional) --
Output array for the quotient to populate. Array must have the same shape as x and the expected data type.
Default:
None.out2 ({None, dpnp.ndarray, usm_ndarray}, optional) --
Output array for the remainder to populate. Array must have the same shape as x and the expected data type.
Default:
None.out (tuple of None, dpnp.ndarray, or usm_ndarray, optional) --
A location into which the result is stored. If provided, it must be a tuple and have length equal to the number of outputs. Each provided array must have the same shape as x and the expected data type. It is prohibited to pass output arrays through out keyword when either out1 or out2 is passed.
Default:
(None, None).order ({None, "C", "F", "A", "K"}, optional) --
Memory layout of the newly output array, if parameter out is
None.Default:
"K".
- Returns:
quotient (dpnp.ndarray) -- Element-wise quotient resulting from floor division.
remainder (dpnp.ndarray) -- Element-wise remainder from floor division.
Limitations
Parameters where, dtype and subok are supported with their default values. Keyword argument kwargs is currently unsupported. Otherwise
NotImplementedErrorexception will be raised.Notes
At least one of x1 or x2 must be an array.
If
x1.shape != x2.shape, they must be broadcastable to a common shape (which becomes the shape of the output).Equivalent to \((x1 // x2, x1 \% x2)\), but faster because it avoids redundant work. It is used to implement the Python built-in function
divmodondpnp.ndarray.Complex dtypes are not supported, they will raise a
TypeError.See also
dpnp.floor_divideEquivalent to Python's \(//\) operator.
dpnp.remainderEquivalent to Python's \(\%\) operator.
dpnp.modfEquivalent to
divmod(x, 1)for positive x with the return values switched.
Examples
>>> import dpnp as np >>> np.divmod(np.arange(5), 3) (array([0, 0, 0, 1, 1]), array([0, 1, 2, 0, 1]))
The Python built-in function
divmodfunction can be used as a shorthand fornp.divmodondpnp.ndarray.>>> x = np.arange(5) >>> divmod(x, 3) (array([0, 0, 0, 1, 1]), array([0, 1, 2, 0, 1]))