Rate This Document
Findability
Accuracy
Completeness
Readability

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

Parameter

Type

Default Value

Description

out

ndarray/ndarray tuple

None

Location where the calculation result is stored. If provided, it must have a shape that the inputs broadcast to. If not provided, a freshly-allocated array is returned.

where

array_like

None

This condition is broadcast over the input. At locations where the condition is true, the out array stores the result. Elsewhere, the out array retains its original value.

**kwargs

-

-

Other keyword arguments. Refer to the NumPy official document Universal functions (ufunc).

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])
>>>