Have you checked torch.narrow, you can get a slice of your tensor then apply sum(axis=1) but the elements in tensor c should have the same value else it won’t return a result. Other than that looks like you really need to use loops.