Block 13: Indexing & Slicing (1D)
Select individual elements and sub-arrays from 1D arrays.
Concepts
- Zero-based positive indexing
- Negative indexing from the end
- Slicing: arr[start:stop:step]
- Slice assignment
Code Examples
See exercise below.
Exercise
From np.arange(100), extract: first 10 elements, last 5, every other element. Reverse an array using slicing.
Homework
Write a function first_n_evens(arr, n) that returns the first n even-indexed elements.