Running batch through custom function

I am trying to run a batch of tensors from my dataloader through a custom function. I have normalised them and simply want to unnormalise it. This is the function:

def unnormalise(height, width, x):
    x = np.asarray(x.cpu().detach().numpy())
    if sum(x) == 0:
        x = x
    else:
        x1 = ((x[0] + 1) * width) / 2
        x2 = ((x[1] + 1) * height) / 2
        x3 = ((x[2] + 1) * width) / 2
        x4 = ((x[3] + 1) * height) / 2
        x = [x1, x2, x3, x4]

It works fine as part of my dataloader (I believe it is because only one value is given rather than a batch) but it doesn’t work when there are multiple values. The batch size i am currently using is 4.

This is the unnormalised values:

tensor([[200.90,  85.31,  14.35,  43.75],
        [  0.00,   0.00,   0.00,   0.00],
        [ 53.20,  97.12,   9.45,  22.75],
        [114.10,  88.81,  13.30,  14.88]]) 

I tried this:

i = 0
for i in range(4):
    x_ = unnormalise(224, 224, x[i])
    print(x)
    i += 1

but that only gives me the data for the final tensor. The print(x) shows that it is correctly unnormalising each tensor in the batch but only outputs the final tensor as x_.

print(x):

tensor([200.90,  85.31,  14.35,  43.75])
tensor([0., 0., 0., 0.])
tensor([53.20, 97.12,  9.45, 22.75])
tensor([114.10,  88.81,  13.30,  14.88])
print(x_): tensor([114.10,  88.81,  13.30,  14.88])

Any advise to help me obtain all 4 values would be greatly appreciated.

I have managed to work it out:

list = []
i = 0
for i in range(4):
    list.append(unnormalise(224, 224, x[i]))
    i += 1