Remove zero dimension in pytorch
I have torch.tensor which has dimension of 0 x 240 x 3 x 540 x 960
I just want to remove 0 dimension, so I want to have pytorch tensor
size of 240 x 3 x 540 x 960.
I used tensor= torch.squeeze(tensor) to try that, but zero dimension was not removed...
In my case, the size of tensor is variable so I can't hard code it to torch.squeeze..
Is there any simple way to remove undesired dimension in pytorch.tensor?

You can't.
The size (=number of elements) in a tensor of shape 0 x 240 x 3 x 540 x 960 is 0.
You can't reshape it to a tensor of shape 240 x 3 x 540 x 960 because that has 373248000 elements.
squeeze() doc:

Returns a tensor with all the dimensions of input of size 1 removed.

This removes 1 sized dims, not 0 sized dims, which makes sense.

Anyway, the amount of data in your original tensor is 0, which can be presented as any shape with at least one zero dim, but not as shapes whose size &gt; 0.
