How to change the shape of tensor

I have a tensor and the shape of it is 7x748. However, I want to reshape it to 7x748x1, and I use the torch.view
for example, data.view(7, 748,1), but it does not work. Could anyone give me some advice to reshape the data to (7,748,1)?

Try data.view(7748,1), you don’t need the comma.

Why doesn’t it work?
x = x.view(7, 748, 1) should return your desired tensor.
Alternatively you could use .unsqueeze(2).

1 Like

yeah, I made a mistake, and x = x.view(7, 748, 1) does work