You've learned how to access data within tensors using indexing and slicing, and how to change a tensor's shape with reshape
, squeeze
, and unsqueeze
. Let's combine these skills to manipulate tensors like a pro.
Engagement Message
Ready to test your tensor navigation and shaping abilities?
Type
Fill In The Blanks
Markdown With Blanks
Fill in the blanks to reshape the 1D tensor data
into a 2x3 tensor. The code will then select the element 5
.
Suggested Answers
- 2
- 3
- 1
- 6
Type
Multiple Choice
Practice Question
A tensor has a shape of (1, 5, 1, 3)
. What will its shape be after applying .squeeze()
?
A. (1, 5, 1, 3) B. (5, 3) C. (1, 5, 3) D. (5, 1, 3)
Suggested Answers
- A
- B - Correct
- C
- D
Type
Sort Into Boxes
Practice Question
Sort these operations based on their primary function.
Labels
- First Box Label: Changes Shape
- Second Box Label: Selects Data
First Box Items
- reshape
- squeeze
- unsqueeze
- transpose
Second Box Items
- indexing
- slicing
Type
Swipe Left or Right
Practice Question
A tensor has 18 elements. Is the target shape a valid reshape operation? Swipe left for valid and right for invalid.
Labels
- Left Label: Valid Reshape
- Right Label: Invalid Reshape
Left Label Items
- (2, 9)
- (3, 6)
- (18, 1)
- (2, 3, 3)
Right Label Items
- (3, 7)
- (2, 8)
Type
Multiple Choice
Practice Question
You have a single image tensor with shape (28, 28)
. To process it in a batch, a model expects an input shape of (1, 28, 28)
. Which operation should you use?
A. tensor.squeeze(0) B. tensor.reshape(1, 28, 28) C. tensor.unsqueeze(0) D. Both B and C are correct
Suggested Answers
- A
- B
- C
- D - Correct
Type
Fill In The Blanks
Markdown With Blanks
Complete the code to select the first element of the tensor and then expand it into a shape of (1, 1)
.
Suggested Answers
- 0
- unsqueeze
- squeeze
