September 2019
Intermediate to advanced
420 pages
10h 29m
English
If you have used Python's standard list indexing before, then you won't find many issues with indexing in NumPy. In a 1D array, the ith value (counting from zero) can be accessed by specifying the desired index in square brackets, just as with Python lists:
In [13]: int_arrOut[13]: array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])In [14]: int_arr[0]Out[14]: 0In [15]: int_arr[3]Out[15]: 3
To index from the end of the array, you can use negative indices:
In [16]: int_arr[-1]Out[16]: 9In [17]: int_arr[-2]Out[17]: 8
There are a few other cool tricks for slicing arrays, as follows:
In [18]: int_arr[2:5] # from index 2 up to index 5 - 1Out[18]: array([2, 3, 4])In [19]: int_arr[:5] # from the beginning up to index ...
Read now
Unlock full access