You could probably directly index the mapping as seen here:
# create input
x = torch.arange(2*3*32*32).to(torch.uint8)
x = x.view(2, 3, 32, 32)
print(x)

# create mapping by shifting it by 1
mapping = torch.arange(0, 256, dtype=torch.uint8) + 1
# mapping[index] would contain the new value

# index into mapping directly and assign to the result tensor
result = mapping[x.view(-1).long()]
# reshape back
result = result.view(2, 3, 32, 32)
print(result)

# your approach
X = x.clone()
result_X  = X
key = mapping
for batch_i in range(X.shape[0]):
    for channel_j in range(X.shape[1]):
        for row_k in range(X.shape[2]):
            for col_l in range(X.shape[3]):
                previous = X[batch_i][channel_j][row_k][col_l]
                previous = previous.item()
                result_X[batch_i][channel_j][row_k][col_l] = key[previous]

# compare
print((result == result_X).all())
> tensor(True)