mode
- paddle. mode ( x: Tensor, axis: int = -1, keepdim: bool = False, name: str | None = None, *, out: tuple[Tensor, Tensor] | None = None ) ModeRetType [source]
-
Used to find values and indices of the modes at the optional axis.
- Parameters
-
x (Tensor) – Tensor, an input N-D Tensor with type float32, float64, int32, int64. Alias:
input.axis (int, optional) – Axis to compute indices along. The effective range is [-R, R), where R is x.ndim. when axis < 0, it works the same way as axis + R. Default is -1. Alias:
dim.keepdim (bool, optional) – Whether to keep the given axis in output. If it is True, the dimensions will be same as input x and with size one in the axis. Otherwise the output dimensions is one fewer than x since the axis is squeezed. Default is False.
name (str|None, optional) – For details, please refer to api_guide_Name. Generally, no setting is required. Default: None.
- Keyword Arguments
-
out (tuple(Tensor), optional) – The output tensor.
- Returns
-
tuple (Tensor), return the values and indices. The value data type is the same as the input x. The indices data type is int64.
Examples
>>> import paddle >>> tensor = paddle.to_tensor( ... [ ... [[1, 2, 2], [2, 3, 3]], ... [[0, 5, 5], [9, 9, 0]], ... ], ... dtype=paddle.float32, ... ) >>> values, indices = paddle.mode(tensor, 2) >>> print(values) Tensor(shape=[2, 2], dtype=float32, place=Place(cpu), stop_gradient=True, [[2., 3.], [5., 9.]]) >>> print(indices) Tensor(shape=[2, 2], dtype=int64, place=Place(cpu), stop_gradient=True, [[2, 2], [2, 1]])
