Challenge - 5 Problems
Ellipsis Indexing Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of ellipsis indexing on 3D array
What is the output of the following code snippet?
NumPy
import numpy as np arr = np.arange(27).reshape(3,3,3) result = arr[..., 1] print(result)
Attempts:
2 left
💡 Hint
Ellipsis (...) replaces all missing full slices in the indexing.
✗ Incorrect
The ellipsis selects all elements in the first two dimensions and fixes the last dimension at index 1, resulting in a 2D array of shape (3,3).
❓ data_output
intermediate1:30remaining
Shape after ellipsis indexing
Given a 4D numpy array with shape (2,3,4,5), what is the shape of the result after indexing with arr[1, ..., 2]?
NumPy
import numpy as np arr = np.zeros((2,3,4,5)) result = arr[1, ..., 2] print(result.shape)
Attempts:
2 left
💡 Hint
Ellipsis fills in the missing dimensions. The fixed indices reduce dimensions accordingly.
✗ Incorrect
Indexing arr[1, ..., 2] fixes the first dimension at 1 and the last dimension at 2, leaving the middle two dimensions (3,4) intact.
🔧 Debug
advanced1:30remaining
Identify the error in ellipsis indexing
What error does the following code raise?
NumPy
import numpy as np arr = np.arange(24).reshape(2,3,4) result = arr[..., 4] print(result)
Attempts:
2 left
💡 Hint
Check the size of the last dimension and the index used.
✗ Incorrect
The last dimension has size 4, so index 4 is out of bounds (valid indices are 0 to 3).
🚀 Application
advanced1:30remaining
Using ellipsis to select all but one dimension
You have a 5D numpy array with shape (2,3,4,5,6). Which indexing expression selects all elements in the first four dimensions but only the element at index 2 in the last dimension?
Attempts:
2 left
💡 Hint
Ellipsis replaces multiple full slices.
✗ Incorrect
arr[..., 2] means select all in all dimensions except the last, where index 2 is fixed.
🧠 Conceptual
expert2:00remaining
Ellipsis behavior with mixed indexing
Consider a numpy array arr with shape (3,4,5,6). What is the shape of arr[1, ..., 2:4]?
NumPy
import numpy as np arr = np.zeros((3,4,5,6)) result = arr[1, ..., 2:4] print(result.shape)
Attempts:
2 left
💡 Hint
Ellipsis fills missing dimensions. Slicing keeps dimension size.
✗ Incorrect
Index 1 fixes the first dimension (3 → removed). Ellipsis fills next two dimensions (4,5). The slice 2:4 selects 2 elements in last dimension (6 → 2).