megengine.functional.maximum

maximum(x, y)[source]

Element-wise maximum of tensor elements.

Compare two tensors and returns a new tensor containing the element-wise maxima. If one of the elements being compared is a NaN, then that element is returned. If both elements are NaNs then the first is returned.

Parameters
  • x – input tensor. Should have a numeric data type.

  • y – input tensor. Should have the same data type as \(x\).

Returns

a tensor containing the element-wise maxima. The returned tensor must have the same data type as \(x\).

Examples

>>> F.maximum(1, 2)
Tensor(2, dtype=int32, device=xpux:0)

Element-wise maximum:

>>> x = Tensor([1, 2, 3, 4])
>>> y = Tensor([4, 3, 2, 1])
>>> F.maximum(x, y)
Tensor([4 3 3 4], dtype=int32, device=xpux:0)

Broadcasting:

>>> x = Tensor([1, 2, 3, 4])
>>> F.maximum(x, 2)
Tensor([2 2 3 4], dtype=int32, device=xpux:0)