How to change shape of a matrix without dispositioning the elements

Yes, that would still work.

Reshape preserves the ordering of x[0][0][0], x[0][0][1], ... x[m-1][n-1][p-1].

Reshape will not be appropriate if you have an input of shape (bs, seq_len, input_size) and want to pass it into the LSTM that takes (seq_len, bs, input_size). There you would need to use permute to transpose the dims: lstm_input = x.permute(1, 0, 2)

2 Likes