Reputation: 1537
I have a tensor with this size
torch.Size([128, 64])
how do I add one "dummy" dimension such as
torch.Size([1, 128, 64])
Upvotes: 1
Views: 2964
Reputation: 114976
There are several ways:
torch.unsqueeze(x, 0)
Using None
(or np.newaxis
):
x[None, ...]
# or
x[np.newaxis, ...]
x.reshape(1, *x.shape)
# or
x.view(1, *x.shape)
Upvotes: 3