How to do a groupby in torch tensor?

Could you help me with a problem? :smile:

I have a tensor like this:

labels = [0,0,0,1,…,1998]
samples = [1,20,3,…,3]

I need to pick for the same class, the maximun value of samples. E.g in the previous tensor the result must be:

[1998, _ ]]

Thank you in advance for your help.