From the docs:
Returns a new tensor with the same data as the
self
tensor but of a differentshape
.
The returned tensor shares the same data and must have the same number of elements, but may have a different size. For a tensor to be viewed, the new view size must be compatible with its original size and stride, i.e., each new view dimension must either be a subspace of an original dimension, or only span across original dimensions …
In other words: view
is similar to reshape
, but doesn’t trigger a copy of the tensor.
The values passed to view
are used as the shape of the view.