You could try to do it via binary masking and indexing like this:
new_tensor = tensor[tensor!=0]

Edit: you would have to create a tensor of zeros, as you don’t have any control over the content of an empty tensor.