mode

paddle. mode ( x, axis=- 1, keepdim=False, name=None ) [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.

  • 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.

  • 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 dimentions is one fewer than x since the axis is squeezed. Default is False.

  • name (str, optional) – For details, please refer to Name. Generally, no setting is required. Default: None.

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)
>>> res = paddle.mode(tensor, 2)
>>> print(res)
(Tensor(shape=[2, 2], dtype=float32, place=Place(cpu), stop_gradient=True,
[[2., 3.],
 [5., 9.]]), Tensor(shape=[2, 2], dtype=int64, place=Place(cpu), stop_gradient=True,
[[2, 2],
 [2, 1]]))