I want to change the input form(batch, timesteps, features) into (timesteps, batch, features), but i don’t understand the difference between permute() and view(), and which one to use.
You should use permute
, as otherwise you’ll just get a new view on the same data using different strides.
Here is a small example:
batch_size = 2
time_steps = 3
features = 4
x = torch.arange(batch_size*time_steps*features).view(batch_size, time_steps, features)
print(x[0])
y = x.permute(1, 0, 2)
print(y[:, 0]) # Same as x[0]
z = x.view(time_steps, batch_size, features)
print(z[:, 0]) # NOT the same!
Thank you, it helps a lot.