Last active
July 23, 2021 06:58
-
-
Save maxrohleder/3decf02f8edc48c663aa78209b514554 to your computer and use it in GitHub Desktop.
smart indexing can save you a lot of looping
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a = np.array([[0, 1, 2], | |
[3, 4, 5]]) | |
b = np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) | |
# subsetting of the array (start is included, end is excluded) | |
print(a[0:2, 0:2]) | |
#> [[0 1] | |
#> [3 4]] | |
# striding / stepping "every second entry" | |
print(b[::2]) | |
#> [0 2 4 6 8] | |
# indexing from back to front | |
print(b[-1], b[-3]) | |
#> 9 7 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment