The tensor t is 1D with shape (5,). It has only one dimension.
Step 2: Check indexing used
The code uses t[::2, 1] which tries to index two dimensions (rows and columns). This causes an error because t is 1D.
Final Answer:
Trying to index 2D on a 1D tensor -> Option A
Quick Check:
1D tensor cannot be indexed with two indices [OK]
Hint: Match number of indices to tensor dimensions [OK]
Common Mistakes:
Assuming 1D tensor can be indexed like 2D
Confusing slicing syntax with indexing
Ignoring tensor shape before indexing
5. You have a 3D tensor t with shape (4, 5, 6). Which indexing expression extracts all elements from the second dimension at index 3, across all batches and features?
hard
A. t[:, 3, :]
B. t[3, :, :]
C. t[:, :, 3]
D. t[3, 3, :]
Solution
Step 1: Understand tensor dimensions
Tensor shape is (4, 5, 6): first dim = batches, second dim = 5 elements, third dim = 6 features.
Step 2: Select all batches, index 3 in second dim, all features
Use : to select all in first and third dims, and 3 to select index 3 in second dim, so t[:, 3, :].
Final Answer:
t[:, 3, :] -> Option A
Quick Check:
Colon means all, index 3 picks second dim element [OK]
Hint: Use colon for all dims, index for specific dim [OK]
Common Mistakes:
Mixing dimension order
Using wrong index for dimension
Using single index for multiple dims
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.