megengine.functional.min

min(inp, axis=None, keepdims=False)[源代码]

Calculates the minimum of tensor elements over a given axis (or axes).

参数
  • inp (Tensor) – input tensor. Should have a numeric data type.

  • axis (Union[int, Sequence[int], None]) – axis or axes along which minimums must be computed. By default, the minimum must be computed over the entire tensor. If a sequence of integers, minimums must be computed over multiple axes.

  • keepdims (bool) – if True, the reduced axes (dimensions) must be included in the result as singleton dimensions, and, accordingly, the result must be compatible with the input tensor (see 广播机制与规则). Otherwise, if False, the reduced axes (dimensions) must not be included in the result.

返回类型

Tensor

返回

if the minimum was computed over the entire tensor, a zero-dimensional tensor containing the minimum; otherwise, a non-zero-dimensional tensor containing the minimums.

Special Cases

If \(x_i\) is NaN, the minimum is NaN (i.e., NaN values propagate).

实际案例

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

Along an axis:

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