torch.mode#
- torch.mode(input, dim=-1, keepdim=False, *, out=None)#
返回一個命名元組
(values, indices),其中values是input張量在給定維度dim下每行的眾數(即在該行中出現次數最多的值),而indices是找到的每個眾數的位置索引。預設情況下,
dim是input張量的最後一個維度。如果
keepdim為True,則輸出張量的大小與input相同,只是在dim維度上大小為 1。否則,dim會被壓縮(參見torch.squeeze()),導致輸出張量比input少一個維度。注意
該函式尚未為
torch.cuda.Tensor定義。- 引數
- 關鍵字引數
out (tuple, optional) – the result tuple of two output tensors (values, indices)
示例
>>> b = torch.tensor([[0, 0, 0, 2, 0, 0, 2], ... [0, 3, 0, 0, 2, 0, 1], ... [2, 2, 2, 0, 0, 0, 3], ... [2, 2, 3, 0, 1, 1, 0], ... [1, 1, 0, 0, 2, 0, 2]]) >>> torch.mode(b, 0) torch.return_types.mode( values=tensor([0, 2, 0, 0, 0, 0, 2]), indices=tensor([1, 3, 4, 4, 2, 4, 4]))