0PricingLogin
Deep Learning Academy · Lesson

Reshape, View, Squeeze & Unsqueeze

Change dimensions without copying data.

Same Data, Different Shape

Often the numbers are right but the layout is wrong. Reshaping rearranges a tensor's dimensions without changing the values inside.

reshape Picks a New Layout

Call reshape with the dimensions you want. The total number of elements must stay the same.

x = torch.arange(6)
y = x.reshape(2, 3)
print(y.shape)  # torch.Size([2, 3])

All lessons in this course

  1. Shapes, Dtypes & Indexing
  2. Reshape, View, Squeeze & Unsqueeze
  3. Broadcasting Rules That Save You Loops
  4. Tensors Talk to NumPy
← Back to Deep Learning Academy