NumPy TutorialLesson 5Free preview
NumPy Array Indexing
This lesson is part of NumPy · All levels
Summary
Indexing on the NumPy array allows access to both single and multiple elements at once. For a one-dimensional array, indexing is similar to Python list: arr[0] for the first element and arr[-1] for the last element. In a two-dimensional array, you use a row and column index like a[1, 2], and you can select multiple elements at once with the array as an index.
Key points
- Indexing 1D array is the same as list: it starts from 0 and supports a negative index.
- Indexing the 2D array using the index.
- Can take many elements at once with np.array as an index.
- Boolean arrays can be used as masks to select eligible elements.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.