torch.mode¶
- 
torch.mode(input, dim=- 1, keepdim=False, *, out=None)¶
- Returns a namedtuple - (values, indices)where- valuesis the mode value of each row of the- inputtensor in the given dimension- dim, i.e. a value which appears most often in that row, and- indicesis the index location of each mode value found.- By default, - dimis the last dimension of the- inputtensor.- If - keepdimis- True, the output tensors are of the same size as- inputexcept in the dimension- dimwhere they are of size 1. Otherwise,- dimis squeezed (see- torch.squeeze()), resulting in the output tensors having 1 fewer dimension than- input.- Note - This function is not defined for - torch.cuda.Tensoryet.- Parameters
- Keyword Arguments
- out (tuple, optional) – the result tuple of two output tensors (values, indices) 
 - Example: - >>> a = torch.randint(10, (5,)) >>> a tensor([6, 5, 1, 0, 2]) >>> b = a + (torch.randn(50, 1) * 5).long() >>> torch.mode(b, 0) torch.return_types.mode(values=tensor([6, 5, 1, 0, 2]), indices=tensor([2, 2, 2, 2, 2]))