Why dose tensor.argmax return last index of maximum values?

Based on the documentation, the tensor.argmax should returns the index of the first occurrence of multiple largest values.

But when the tensor contains all same values, it returns the index of the last value.

For example, torch.tensor([0, 0, 0, 0]).argmax(dim=0), outputs is tensor(3). Shouldn’t it be 0?


Which version of pytorch are you using?
This was fixed in 1.7+ versions only IIRC

Got it. Thanks. I was using 1.6.0.

1 Like