0
0
PyTorchml~5 mins

Reshaping (view, reshape, squeeze, unsqueeze) in PyTorch - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the view() function do in PyTorch?

view() changes the shape of a tensor without copying data. It returns a new tensor with the same data but a different shape.

Click to reveal answer
intermediate
How is reshape() different from view() in PyTorch?

reshape() also changes tensor shape but can return a copy if needed, while view() requires the tensor to be contiguous and does not copy data.

Click to reveal answer
beginner
What does squeeze() do to a tensor?

squeeze() removes all dimensions of size 1 from a tensor, making it smaller in shape but keeping the same data.

Click to reveal answer
beginner
How does unsqueeze() modify a tensor?

unsqueeze() adds a dimension of size 1 at a specified position, increasing the tensor's number of dimensions.

Click to reveal answer
beginner
Why is reshaping tensors important in machine learning?

Reshaping helps match tensor shapes for operations like matrix multiplication, batching data, or preparing inputs for models.

Click to reveal answer
Which PyTorch function removes dimensions of size 1 from a tensor?
Asqueeze()
Bunsqueeze()
Creshape()
Dview()
What will tensor.view(-1, 3) do?
AChange tensor shape to have 3 columns and infer rows
BAdd a new dimension of size 3
CRemove all size 1 dimensions
DCopy tensor data to a new tensor
Which function can return a copy of the tensor if needed when reshaping?
Aview()
Breshape()
Csqueeze()
Dunsqueeze()
What does unsqueeze(0) do to a tensor?
ARemoves the first dimension
BFlattens the tensor
CAdds a new dimension at position 0
DChanges tensor data
Why must tensor shapes match for matrix multiplication?
ATo ensure data types match
BTo speed up training
CTo reduce memory usage
DTo align rows and columns correctly
Explain how view() and reshape() differ when changing tensor shapes in PyTorch.
Think about memory layout and copying.
You got /4 concepts.
    Describe a real-life example where you might use squeeze() and unsqueeze() when working with image data.
    Consider how images are stored and fed into models.
    You got /4 concepts.