JamesDickens:

if i = 6 for instance, so I would need if statements.


Why wounldn’t it?
I think that selecting the subset you care about and calling sum is the right thing to do here.
Note that you don’t need to give ranges for dimensions where you want a single value: torch.sum(t[x_min : xmax, y_min:y_max, i, j, c]) but that will give the same result