Guided Notes
Indexing & Slicing
Accessing elements, negative indexes, 2-D indexing, slices with steps, and selecting rows and columns.
Indexing 1-D arrays
Slide 1 / 5Access an element by its index in square brackets. Like Python lists, NumPy counts from 0:
arr = np.array([10, 20, 30, 40]) arr[0] β 10 arr[2] + arr[3] β 70
Negative indexes count from the end: arr[-1] is 40, the last element.
Indexes past the end raise an IndexError β an array of 4 elements has valid indexes 0β3 (or β1 to β4).
