maximum

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

该OP逐元素对比输入的两个Tensor,并且把各个位置更大的元素保存到返回结果中。

等式是:

\[out = max(x, y)\]

注解

paddle.maximum 遵守broadcasting,如您想了解更多,请参见 广播 (broadcasting)

参数

  • x (Tensor)- 输入的Tensor。数据类型为 float32float64int32int64

  • y (Tensor)- 输入的Tensor。数据类型为 float32float64int32int64

  • name (str, 可选)- 操作的名称(可选,默认值为None)。更多信息请参见 Name

返回

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

代码示例

import numpy as np
import paddle

x = paddle.to_tensor([[1, 2], [7, 8]])
y = paddle.to_tensor([[3, 4], [5, 6]])
res = paddle.maximum(x, y)
print(res)
#    [[3, 4],
#     [7, 8]]

x = paddle.to_tensor([[1, 2, 3], [1, 2, 3]])
y = paddle.to_tensor([3, 0, 4])
res = paddle.maximum(x, y)
print(res)
#    [[3, 2, 4],
#     [3, 2, 4]]

x = paddle.to_tensor([2, 3, 5], dtype='float32')
y = paddle.to_tensor([1, np.nan, np.nan], dtype='float32')
res = paddle.maximum(x, y)
print(res)
#    [ 2., nan, nan]

x = paddle.to_tensor([5, 3, np.inf], dtype='float32')
y = paddle.to_tensor([1, -np.inf, 5], dtype='float32')
res = paddle.maximum(x, y)
print(res)
#    [  5.,   3., inf.]