remainder

paddle. remainder ( x, y, name=None ) [源代码]

逐元素取模算子。公式为:

\[\begin{split}\\out = x \% y\\\end{split}\]

注解

paddle.remainder 支持广播,如您想了解更多,请参见 cn_user_guide_broadcasting

参数

  • x (Tensor) - 多维 Tensor。数据类型为 float16 、float32 、float64、int32 或 int64。

  • y (Tensor) - 多维 Tensor。数据类型为 float16 、float32 、float64、int32 或 int64。

  • name (str,可选) - 具体用法请参见 Name ,一般无需设置,默认值为 None。

返回

Tensor,存储运算后的结果。如果 x 和 y 有不同的 shape 且是可以广播的,返回 Tensor 的 shape 是 x 和 y 经过广播后的 shape。如果 x 和 y 有相同的 shape,返回 Tensor 的 shape 与 x,y 相同。

代码示例

import paddle

x = paddle.to_tensor([2, 3, 8, 7])
y = paddle.to_tensor([1, 5, 3, 3])
z = paddle.remainder(x, y)
print(z)  # [0, 3, 2, 1]