view tensor just changes the way it interprets the same data. Taking a
view of contiguous tensor could potentially produce a non-contiguous
tensor. Users should pay additional attention as contiguity might have
implicit performance impact. "transpose()" is a common example.



base = torch.tensor([[0, 1],[2, 3]])
base.is_contiguous()
   True
t = base.transpose(0, 1)  # t is a view of base. No data movement happened here.
   # View tensors might be non-contiguous.
t.is_contiguous()
   False
   # To get a contiguous tensor, call .contiguous() to enforce
   # copying data when t is not contiguous.
c = t.contiguous()



For reference, hereâs a full list of view ops in PyTorch:


Basic slicing and indexing op, e.g. "tensor[0, 2:, 1:7:2]" returns a
  view of base "tensor", see note below.


"adjoint()"


"as_strided()"


"detach()"


"diagonal()"


"expand()"


"expand_as()"


"movedim()"


"narrow()"


"permute()"


"select()"


"squeeze()"


"transpose()"

