I add the contiguous() calls, if the next view operation raises an error. Otherwise I assume PyTorch does the right thing and doesn’t need to create a contiguous copy of the tensor. 



 Igo312:

And how you work it out？right now I regard the array as a one-dimension list and then reshape it.


Do you mean, how do I come up with the solution?
If so, I don’t think there is a better way than having looked at various ways to reshape tensors in the past and just staring long enough at it until you realize which dimension has to move where.
At least I’m not using any formal way and just trust my gut feeling.