Is it possible to remove these two for ?
import torch

a = torch.rand(10, 10)
bz = 4
x_start_index = torch.LongTensor([2, 4, 1, 3])
x_end_index = torch.LongTensor([4, 6, 2, 6])

y_start_index = torch.LongTensor([1, 6, 5, 3])
y_end_index = torch.LongTensor([3, 9, 7, 4])

v_total = []
for i in range(bz):
    # also calculate the sum
    v_tmp = torch.sum(a[x_start_index[i]: x_end_index[i], y_start_index[i]: y_end_index[i]])
    v_total.append(v_tmp)

v_total = torch.stack(v_total)

for i in range(bz):
    # zero out the boxes
    a[x_start_index[i]: x_end_index[i], y_start_index[i]: y_end_index[i]] = 0