Different between permute, transpose, view? Which should I use?

I think you habe it mixed up:

  • permute changes the order of dimensions aka axes, so 2 would be a use case. Transpose is a special case of permute, use it with 2d tensors.
  • view can combine and split axes, so 1 and 3 can use view,
  • note that view can fail for noncontiguous layouts (e.g. crop a picture using indexing), in these cases reshape will do the right thing,
  • for adding dimensions of size 1 (case 3), there also are unsqueeze and indexing with None.

Best regards

Thomas

44 Likes