You can use Tensor.index_add (or here its inplace version) for this:
a = torch.arange(1, 13.).view(4, 3)
b = torch.tensor([0, 0, 1, 2])

c = torch.zeros(3, 3)
c.index_add_(0, b, a)
print(c)

Best regards
Thomas