Indexing
Index into NumPy arrays to extract data and array slices.
We'll cover the following...
We'll cover the following...
Chapter Goals:
- Learn about indexing arrays in NumPy
- Write code for indexing and slicing arrays
A. Array accessing
Accessing NumPy arrays is identical to accessing Python lists. For multi-dimensional arrays, it is equivalent to accessing Python lists of lists.
The code below shows example accesses of NumPy arrays.
B. Slicing
NumPy arrays also support slicing. Similar to Python, we use the colon operator (i.e. arr[:]) for slicing. We can also use negative indexing to slice in the backwards direction.
The code below shows example slices of a 1-D NumPy array.
For multi-dimensional arrays, we can use a comma to separate slices across each dimension.
The code below shows example slices of a 2-D NumPy array.
C. Argmin and argmax
In addition to accessing and slicing arrays, it is useful to figure out the ...