How to do a groupby in torch tensor?

Hi,
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:

[[0,20],
...
[1998, _ ]]

Thank you in advance for your help.