title: A question about pytorch change tensor shape
body: <p>When I want to split an image into multiple patches, the first thing I thought was using pytorch view() function. For example, An image of shape (1,3,256,256)(pytorch style), and split it into 8x8=64 patches, each patch height and width is 32. So for this image, we can get 256/32=8 for row and 8 for column patches, so we total have 8x8=64 patches.</p>
  <p>I want to split the image (1,3,256,256) into patches, each patch shape is (1,3,32,32), and reshape these tensor into shape of (1,8x8,32x32x3), here 8x8 is the number of patches, 32x32x3 is patch height * width * channel.</p>
  <p>Code below use einops rearrange function can get the correct answer, but when I use view function, I got correct shape but incorrect value tensor. Who can tell me how to implement this operation by view function?</p>
  <pre><code>from einops.layers.torch import Rearrange
  img = torch.randn(1, 3, 256, 256)
  import copy
  img2 = copy.deepcopy(img)
  b, c, h, w = img.size()
  p=32
  to_patch_embedding = nn.Sequential(
      Rearrange('b c (h p1) (w p2) -&gt; b (h w) (p1 p2 c)', p1=32, p2=32),
  )
  img2 = img2.view(b, h // p * w // p, c * p * p)
  
  
  print(img2.shape)
  print(img2==to_patch_embedding(img))
  
  ----------------------------------------output--------------------------------------------
  torch.Size([1, 64, 3072])
  tensor([[[ True, False, False,  ..., False, False, False],
       [False, False, False,  ..., False, False, False],
       [False, False, False,  ..., False, False, False],
       ...,
       [False, False, False,  ..., False, False, False],
       [False, False, False,  ..., False, False, False],
       [False, False, False,  ..., False, False,  True]]])
  </code></pre>