mindspore.numpy.fmod(x1, x2, dtype=None)[source]

Returns the element-wise remainder of division.

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(TM) rem function and should not be confused with the Python modulus operator x1 % x2.


Numpy arguments out, where, casting, order, subok, signature, and extobj are not supported.

  • x1 (Tensor) –

  • x2 (Tensor) – input arrays.

  • dtype (mindspore.dtype, optional) – defaults to None. Overrides the dtype of the output Tensor.


Tensor or scalar, the remainder of the division of x1 by x2. This is a scalar if both x1 and x2 are scalars.

Supported Platforms:

Ascend GPU CPU


>>> import mindspore.numpy as np
>>> output = np.fmod(np.array([-3, -2, -1, 1, 2, 3]), np.array(2))
>>> print(output)
[-1  0 -1  1  0  1]