mindspore.ops.remainder

查看源文件
mindspore.ops.remainder(input, other)[源代码]

逐元素计算输入tensor的除法余数。

支持隐式类型转换、类型提升。

remainder(input, other) == input - input.div(other, rounding_mode="floor") * other

警告

  • 当输入元素超过2048时,可能会有精度问题。

  • 在Ascend和CPU上的计算结果可能不一致。

  • 如果shape表示为(D1,D2…Dn),那么D1 * D2……* DN <= 1000000,n <= 8。

参数:
  • input (Union[Tensor, numbers.Number, bool]) - 第一个输入。

  • other (Union[Tensor, numbers.Number, bool]) - 第二个输入。

返回:

Tensor

支持平台:

Ascend GPU CPU

样例:

>>> import mindspore
>>> # case 1: The shape of two inputs are different
>>> x = mindspore.tensor([-4.0, 5.0, 6.0], mindspore.float16)
>>> y = mindspore.tensor([3.0], mindspore.float16)
>>> output = mindspore.ops.remainder(x, y)
>>> print(output)
[2. 2. 0.]
>>> # case 2: The shape of two inputs are the same
>>> x = mindspore.tensor([-4.0, 5.0, 6.0], mindspore.float16)
>>> y = mindspore.tensor([3.0, 2.0, 3.0], mindspore.float16)
>>> output = mindspore.ops.remainder(x, y)
>>> print(output)
[2. 1. 0.]