worked like a charm thanks a lot! I also posted on stackoverflow 139 and got the following alternative which I leave here for future reference:
M = torch.zeros(labels.max()+1, len(samples))
M[labels, torch.arange(4)] = 1
M = torch.nn.functional.normalize(M, p=1, dim=1)
torch.mm(M, samples)