fmod
Description
Return the element-wise remainder of division. Note: This is the NumPy implementation of the C library function fmod. The remainder has the same sign as the dividend x1. It is equivalent to the Matlab rem function and should not be confused with the Python modulus operator x1 % x2.
Mandatory Input Parameters
Parameter |
Type |
Description |
|---|---|---|
x1 |
array_like |
Dividend, which is an input array or scalar |
x2 |
array_like |
Divisor, which is an input array or scalar If x1.shape!=x2.shape, they must be broadcastable to a common shape. |
Optional Input Parameters
Return Value
Type |
Description |
|---|---|
ndarray/scalar |
Result of x1% x2. The result sign is the same as that of x1. |
Examples
>>> import numpy as np >>> np.fmod(-3,2) -1 >>> >>> x1 = [-1, 2, -3, 4, -5] >>> np.fmod(x1, 2) array([-1, 0, -1, 0, -1]) >>> >>> x2 = [1, -1, 2, -2, 3] >>> np.fmod(x1, x2) array([ 0, 0, -1, 0, -2]) >>>
Parent topic: Basic Operation Functions