fmax

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

比较两个 Tensor 对应位置的元素,返回一个包含该元素最大值的新 Tensor。如果两个元素其中一个是 nan 值,则直接返回另一个值,如果两者都是 nan 值,则返回第一个 nan 值。

等式是:

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

备注

paddle.fmax 遵守 broadcasting,如您想了解更多,请参见 Tensor 介绍 .

参数

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

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

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

返回

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

代码示例

>>> import paddle >>> x = paddle.to_tensor([[1, 2], [7, 8]]) >>> y = paddle.to_tensor([[3, 4], [5, 6]]) >>> res = paddle.fmax(x, y) >>> print(res) Tensor(shape=[2, 2], dtype=int64, place=Place(cpu), stop_gradient=True, [[3, 4],  [7, 8]]) >>> x = paddle.to_tensor([[1, 2, 3], [1, 2, 3]]) >>> y = paddle.to_tensor([3, 0, 4]) >>> res = paddle.fmax(x, y) >>> print(res) Tensor(shape=[2, 3], dtype=int64, place=Place(cpu), stop_gradient=True, [[3, 2, 4],  [3, 2, 4]]) >>> x = paddle.to_tensor([2, 3, 5], dtype='float32') >>> y = paddle.to_tensor([1, float("nan"), float("nan")], dtype='float32') >>> res = paddle.fmax(x, y) >>> print(res) Tensor(shape=[3], dtype=float32, place=Place(cpu), stop_gradient=True, [2., 3., 5.]) >>> x = paddle.to_tensor([5, 3, float("inf")], dtype='float32') >>> y = paddle.to_tensor([1, -float("inf"), 5], dtype='float32') >>> res = paddle.fmax(x, y) >>> print(res) Tensor(shape=[3], dtype=float32, place=Place(cpu), stop_gradient=True, [5. , 3. , inf.])