oneflow.mode¶
-
oneflow.mode(input, dim=- 1, keepdim=False)¶ Returns a namedtuple (values, indices) where values is the mode value of each row of the input tensor in the given dimension dim, i.e. a value which appears most often in that row, and indices is the index location of each mode value found.
By default,
dimis the last dimension of theinputtensor.If
keepdimisTrue, the output tensors are of the same size asinputexcept in the dimensiondimwhere they are of size 1. Otherwise,dimis squeezed (seeflow.squeeze()), resulting in the outputs tensor having 1 fewer dimension thaninput.- Parameters
input (Tensor) – the input tensor.
dim (int) – the dimension to reduce. Default: -1
keepdim (bool) – whether the output tensor has dim retained or not. Default: False
- Returns
the result tuple of two output tensors (values, indices)
- Return type
Tuple(oneflow.Tensor, oneflow.Tensor(dtype=int64))
For example:
>>> import oneflow as flow >>> x = flow.tensor([6, 2, 5, 3, 3, 5, 4, 3]) >>> result = flow.mode(x) >>> result.values tensor(3, dtype=oneflow.int64) >>> result.indices tensor(7, dtype=oneflow.int64) >>> x = flow.Tensor([[2, 1, 2, 3], [2, 4, 3, 3]]) >>> result = flow.mode(x, dim=0) >>> result.values tensor([2., 1., 2., 3.], dtype=oneflow.float32) >>> result.indices tensor([1, 0, 0, 1], dtype=oneflow.int64)