numpy.remainder

numpy.remainder(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature, extobj]) = <ufunc 'remainder'>

返回按元素排序的除法余数。

计算与 floor_divide 功能。它等价于python modules运算符“x1%x2”,并且与除数具有相同的符号 x2 . matlab函数等价于 np.remaindermod .

警告

这不应与以下内容混淆:

  • Python 3.7 math.remainder 和C的 remainder ,它计算IEEE余数,这是对 round(x1 / x2) .

  • MATLAB rem 函数和或c % 运算符,它是对 int(x1 / x2) .

参数
x1array_like

红利数组。

x2array_like

除数数组。如果 x1.shape != x2.shape ,它们必须可以广播到公共形状(成为输出的形状)。

outndarray、none或ndarray和none的元组,可选

存储结果的位置。如果提供,它必须具有输入广播到的形状。如果未提供或没有,则返回新分配的数组。元组(只能作为关键字参数)的长度必须等于输出数。

where阵列式,可选

这种情况通过输入广播。在条件为真的位置 out 数组将被设置为ufunc结果。在其他地方 out 数组将保留其原始值。请注意,如果未初始化 out 数组是通过默认值创建的 out=None ,其中条件为False的位置将保持未初始化状态。

**kwargs

有关其他仅限关键字的参数,请参见 ufunc docs .

返回
y恩达雷

商的元素余数 floor_divide(x1, x2) . 这是一个标量,如果两者都是 x1x2 是标量。

参见

floor_divide

相当于python // 操作员。

divmod

同时进行楼层划分和余数。

fmod

相当于matlab rem 功能。

divide, floor

笔记

返回0时 x2 是0和二者兼而有之 x1x2 是整数的(数组)。 mod 是的别名 remainder .

实例

>>> np.remainder([4, 7], [2, 3])
array([0, 1])
>>> np.remainder(np.arange(7), 5)
array([0, 1, 2, 3, 4, 0, 1])

这个 % 运算符可用作 np.remainder 在星期天。

>>> x1 = np.arange(7)
>>> x1 % 5
array([0, 1, 2, 3, 4, 0, 1])