Recall & Review
beginner
What does the ellipsis (...) represent in NumPy indexing?
The ellipsis (...) in NumPy indexing means 'include all the remaining dimensions here'. It helps to select slices across multiple dimensions without writing all indices explicitly.
Click to reveal answer
beginner
How would you select all elements in the last two dimensions of a 4D array using ellipsis?
You can use arr[..., :, :] to select all elements in the last two dimensions, regardless of the size of the first two dimensions.
Click to reveal answer
beginner
True or False: The ellipsis can only be used once in a NumPy indexing expression.
True. You can only use one ellipsis (...) in a single NumPy indexing expression.
Click to reveal answer
beginner
Given a 3D array arr with shape (3, 4, 5), what does arr[1, ...] select?
It selects all elements in the last two dimensions for the first dimension index 1. So the shape of arr[1, ...] is (4, 5).
Click to reveal answer
intermediate
Why is using ellipsis helpful when working with arrays of varying dimensions?
Ellipsis lets you write flexible code that works with arrays of different shapes by automatically including all remaining dimensions without specifying each one.
Click to reveal answer
What does arr[..., 0] select in a 3D array arr?
✗ Incorrect
The ellipsis (...) means all preceding dimensions, so arr[..., 0] selects the element at index 0 in the last dimension for all other dimensions.
Can you use more than one ellipsis (...) in a single NumPy indexing expression?
✗ Incorrect
NumPy allows only one ellipsis (...) per indexing expression to avoid ambiguity.
If arr has shape (2, 3, 4, 5), what is the shape of arr[1, ..., 2]?
✗ Incorrect
arr[1, ..., 2] fixes the first dimension at 1 and the last dimension at 2, leaving the middle two dimensions (3, 4).
What is the main benefit of using ellipsis in NumPy indexing?
✗ Incorrect
Ellipsis helps write shorter, flexible code that works with arrays of different shapes by including all remaining dimensions automatically.
Which of the following is a valid use of ellipsis in NumPy?
✗ Incorrect
Only one ellipsis is allowed per indexing expression, so arr[1, ..., 2] is valid, others are not.
Explain how the ellipsis (...) works in NumPy indexing and give an example with a 3D array.
Think about how you can avoid writing all indices for multi-dimensional arrays.
You got /3 concepts.
Describe a situation where using ellipsis in indexing makes your code more flexible.
Consider working with data that can have different shapes.
You got /3 concepts.