-
-
Save collinalexbell/a25560e5e72d58978f3dedbab407983e to your computer and use it in GitHub Desktop.
Regarding multi-dim indexing of numpy arrays
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([[1,2,3],[4,5,6]]) | |
>>> a | |
array([[1, 2, 3], | |
[4, 5, 6]]) | |
>>> b = [1,2] | |
>>> a[:, b] | |
array([[2, 3], | |
[5, 6]]) | |
>>> a[np.arange(len(a)), b] | |
array([2, 6]) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment