Recall & Review
beginner
What does the slicing notation
start:stop:step mean in numpy arrays?It means to select elements from the array starting at index
start, up to but not including stop, taking every stepth element.Click to reveal answer
beginner
What happens if you omit
start in start:stop:step slicing?If
start is omitted, slicing starts from the beginning of the array (index 0).Click to reveal answer
intermediate
How does a negative
step value affect slicing in numpy?A negative
step means slicing goes backwards, selecting elements in reverse order.Click to reveal answer
beginner
Given
arr = np.array([10, 20, 30, 40, 50]), what does arr[1:4:2] return?It returns
array([20, 40]) because it starts at index 1 (20), goes up to index 4 (not including 4), taking every 2nd element.Click to reveal answer
beginner
What is the result of
arr[::-1] for a numpy array arr?It returns the array reversed, selecting all elements with a step of -1.
Click to reveal answer
In numpy slicing
arr[start:stop:step], what does stop represent?✗ Incorrect
The stop index is where slicing stops, but this index is not included in the result.
What does
arr[::2] do?✗ Incorrect
Omitting start and stop means the whole array is sliced, taking every 2nd element.
What is the output of
arr[3:0:-1] for arr = np.array([5,10,15,20,25])?✗ Incorrect
Starts at index 3 (20), goes backwards to index 1 (not including 0), stepping -1.
If
step is negative, what must be true about start and stop?✗ Incorrect
When stepping backwards, slicing moves from a higher index to a lower index.
What does
arr[:] do?✗ Incorrect
Omitting start, stop, and step returns the whole array as a slice (a view or copy).
Explain how slicing with
start:stop:step works in numpy arrays.Think about how you pick items from a list skipping some.
You got /4 concepts.
Describe what happens when you use a negative step in numpy slicing and give an example.
Imagine reading a list from the end to the start.
You got /3 concepts.