maxframe.tensor.remainder#

maxframe.tensor.remainder(x1, x2, out=None, where=None, **kwargs)#

返回逐元素的除法余数。

计算与 floor_divide 函数互补的余数。它等价于 Python 取模运算符 x1 % x2,并且符号与除数 x2 相同。MATLAB 中与 np.remainder 等价的函数是 mod

警告

这不应与以下内容混淆:

  • Python 3.7 的 math.remainder 和 C 的 remainder,它们计算 IEEE 余数,是 round(x1 / x2) 的补运算。

  • MATLAB 的 rem 函数或 C 的 % 运算符,它们是 int(x1 / x2) 的补运算。

参数:
  • x1 (array_like) -- 被除数数组。

  • x2 (array_like) -- 除数数组。

  • out (Tensor, None, or tuple of Tensor and None, optional) -- 用于存储结果的位置。如果提供,其形状必须可以广播到输入形状。如果未提供或者为 None,则返回一个新分配的张量。元组(只能作为关键字参数)的长度必须等于输出数量。

  • where (array_like, optional) -- 为 True 的值表示在该位置计算 ufunc,为 False 的值表示保留输出中的值不变。

  • **kwargs

返回:

y -- 商 floor_divide(x1, x2) 的逐元素余数。如果 x1x2 都是标量,则返回标量。

返回类型:

Tensor

参见

floor_divide

等价于 Python 的 // 运算符。

divmod

同时进行向下取整除法和求余。

fmod

等价于 MATLAB 的 rem 函数。

divide, floor

备注

x2 为 0 且 x1x2 都是(张量形式的)整数时,返回 0。

示例

>>> import maxframe.tensor as mt
>>> mt.remainder([4, 7], [2, 3]).execute()
array([0, 1])
>>> mt.remainder(mt.arange(7), 5).execute()
array([0, 1, 2, 3, 4, 0, 1])