is there any way torch.mode can be applied over multiple dimensions

for example

import numpy as npimport torchx = np.random.randint(10, size=(3, 5))y = torch.tensor(x)

lets say y has

[[6 3 7 3 0][2 5 7 9 7][6 1 4 6 3]]

torch.mode should return a size 3 tensor [3,7,6]

without using a loop

1

Best Answer


Use the dimension attribute in torch to select which dimension should be reduced using mode operator.

torch.mode(y, dim = 1)[0]

Will give you the desired answer.