The divmod()
function in Python obtains the quotient and remainder of the division two input arrays, x1
, and x2
, element-wise.
numpy.divmod(x1, x2, /, out=None, *, where=True)
The divmod()
function takes the following parameter values:
x1
: This represents an input array of elements which are the dividends. This is a required parameter. x2
: This represents the divisor array. This is a required parameter. out
: This represents the location where the result is stored. This is an optional parameter. where
: This is the condition over which the input is being broadcast. At a given location where this condition is True
, the resulting array will be set to the ufunc
result. Otherwise, the resulting array will retain its original value. This is an optional parameter. ufunc
is short for universal function, and it operates onndarrays()
, in an element-wise fashion. It also supports other standard features in NumPy.
**kwargs
: This represents other keyword arguments. This is an optional parameter. The divmod()
function returns an array showing the element-wise quotient and remainder of the division of two arrays simultaneously.
import numpy as np# creating input arraysx1 = np.array([6, 6, 6])x2 = np.array([2, 4, 6])# implementing the divmod() functionmyarray = np.divmod(x1, x2)print(x1)print(x2)print(myarray)
numpy
module.x1
and x2
, using the array()
function.numpy.divmod()
function on the input arrays. We assign the result to a variable, myarray
.x1
and x2
to the console.myarray
to the console. The myarray
variable holds the result from the numpy.divmod()
function implementation.