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).