Indexing an NumPy Array
Indexing is used to extract individual elements from a one-dimensional array.
It can also be used to extract rows, columns, or planes in a multi-dimensional NumPy array.
Example: Index in NumPy array
Element | 23 | 21 | 55 | 65 | 23 |
---|---|---|---|---|---|
Index | 0 | 1 | 2 | 3 | 4 |
In the above example, we have highlighted the element “55” which is at index “2”.
Let’s discuss different methods to perform indexing in the NumPy array:
Basic Slicing and Advanced Indexing in NumPy
Indexing a NumPy array means accessing the elements of the NumPy array at the given index.
There are two types of indexing in NumPy: basic indexing and advanced indexing.
Slicing a NumPy array means accessing the subset of the array. It means extracting a range of elements from the data.
In this tutorial, we will cover basic slicing and advanced indexing in the NumPy. NumPy arrays are optimized for indexing and slicing operations making them a better choice for data analysis projects.
Prerequisites
Numpy in Python Introduction