The mod()
function in NumPy returns the remainder from the division of two arrays, element-wise.
numpy.fmod(x1, x2, /, out=None, *, where=True)
The mod()
function takes the following parameter values:
x1
: This represents the input array of elements that are the dividends. This is a required parameter.x2
: This represents an array of elements that are the divisors. This is also 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 also an optional parameter.**kwargs
: This represents other keyword arguments. This is also an optional parameter.import numpy as np# creating input arraysx1 = np.array([1, 2, 3])x2 = np.array([1, 2, 2])# implementing the mod() functionmyarray = np.mod(x1, x2)print(x1)print(x2)print("The element-wise remainders values of the division are: ", myarray)
numpy
module.x1
and x2
, using the array()
function.numpy.mod()
function on the input arrays. We assign the result to a variable myarray
.x1
and x2
to the console.myarray
to the console.