Recall & Review
beginner
What is indexing in PyTorch tensors?
Indexing means selecting a single element from a tensor using its position, like picking one item from a list by its number.
Click to reveal answer
beginner
How does slicing work in PyTorch tensors?
Slicing means selecting a range of elements from a tensor, similar to cutting a piece from a loaf of bread by specifying start and end positions.
Click to reveal answer
beginner
What does the colon ':' symbol mean in tensor slicing?
The ':' means 'take all elements' along that dimension, like saying 'give me everything in this row or column'.
Click to reveal answer
intermediate
How do you select the first 3 rows and last 2 columns of a 2D tensor in PyTorch?
Use slicing like tensor[:3, -2:] which means 'rows from start to 3 (not including 3)' and 'last 2 columns'.
Click to reveal answer
intermediate
What happens if you use a negative index in PyTorch tensor indexing?
Negative index counts from the end, so -1 means the last element, -2 means second last, just like counting backwards in a list.
Click to reveal answer
In PyTorch, what does tensor[2] select?
✗ Incorrect
Indexing starts at 0, so tensor[2] selects the element at position 2, which is the third element.
What does tensor[:, 1:4] do?
✗ Incorrect
The ':' means all rows, and '1:4' means columns from 1 up to but not including 4.
How do you select the last element of a tensor?
✗ Incorrect
Negative indexing with -1 selects the last element.
What does tensor[1:5:2] mean?
✗ Incorrect
The slice 1:5:2 means start at 1, go up to but not including 5, stepping by 2.
If tensor is 3D, what does tensor[:, 0, :] select?
✗ Incorrect
The ':' means all elements in that dimension, '0' selects the first element in the second dimension.
Explain how to use indexing and slicing to select parts of a PyTorch tensor.
Think about how you pick items from a list or a grid.
You got /4 concepts.
Describe how negative indices work in PyTorch tensor indexing and slicing.
Imagine counting backwards from the end of a line.
You got /4 concepts.