Reputation: 352
I am new to pytorch. I have 3D tensor (32,10,64) and I want a 2D tensor (32, 64). I tried view() and used after passing to linear layer squeeze() which converted it to (32,10).
view()
squeeze()
Upvotes: 1
Views: 15897
Reputation: 2157
Try this
t = torch.rand(32, 10, 64).permute(0, 2, 1)[:, :, -1]
or, as pointed out by Shai, you could also
t = torch.rand(32, 10, 64)[:, -1, :] print(t.size()) # torch.Size([32, 64])
Upvotes: 3