ptrblck:

tgt = torch.tensor([3, 7, 3, 5, 11, 11, 11])
probs = torch.tensor([-0.2, -0.4, -0.5, -0.8, -0.1, -0.7, -0.2])



Thanks for your response!
But if I’m not mistaken, this solution is only good for the 1-dimensional case. My example was with 1 dimension, but the problem is regarding the 2 dimensional case.
For example:
tgt = torch.tensor([[3, 7, 3, 5, 11, 11, 11],[1, 1, 1, 4, 11, 15, 4]])
probs = torch.tensor([[-0.2, -0.4, -0.5, -0.8, -0.1, -0.7, -0.2],[-0.1, -0.9, -0.1, -0.4, -0.3, -0.3, -0.8]]) 

summed_probs = [[-0.7, -0.4, -0.7, -0.8, -1.0, -1.0, -1.0],[-1.1, -1.1, -1.1, -1.2, -0.3, -0.3, -1.2]]
# OR
summed_probs = [[(3, -0.7),(7, -0.4), (5, -0.8), (11, -1.0)],[(1, -1.1),(4, -1.2, (11, -0.3), (15, -0.3)]]