Thanks for the answer.

The reason is that it wouldn’t make sense to use a Python list if you want something to be in a fixed-size array later on.

Good point

A list would be super inefficient because it would allocate more memory on the fly when you append and it’s running out of allocated memory, and in the worst case, it can allocate approx twice as memory as needed.

The python list contains only references, so the problem you worry about will never happens.

I would probably also specify the dtype in torch.empty_like.

torch.empty_like does not only copy the size but also dtype and device.

the ideal way regarding computing and memory resources would be to modify/override the values in the input tensor directly

Good point, I will try to do that !