torch.mode¶
-
torch.
mode
(input, dim=-1, keepdim=False, out=None) -> (Tensor, LongTensor)¶ Returns a namedtuple
(values, indices)
wherevalues
is the mode value of each row of theinput
tensor in the given dimensiondim
, i.e. a value which appears most often in that row, andindices
is the index location of each mode value found.By default,
dim
is the last dimension of theinput
tensor.If
keepdim
isTrue
, the output tensors are of the same size asinput
except in the dimensiondim
where they are of size 1. Otherwise,dim
is squeezed (seetorch.squeeze()
), resulting in the output tensors having 1 fewer dimension thaninput
.Note
This function is not defined for
torch.cuda.Tensor
yet.- Parameters
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]))