[resolved] Double unsqueeze

Hi,

Is there a smart way to do: my_tensor.unsqueeze(0).unsqueeze(0) in one shot?

something like my_tensor.unsqueeze(0,1)

It’s not a big deal but if you want to had 3 fake dimensions, the code line stops to look serious

How, just my_tensor.view(1,1,-1) did it… ok sorry for the topic…

5 Likes

This flattens the -1 dimension

1 Like

you can use my_tensor(*my_tensor.shape,1,1)

This was one of the first results in Google, so for anybody out there, if you don’t want to flatten the last dim, my_tensor[None, None, ...] currently does the job.

1 Like