Skip to content

Instantly share code, notes, and snippets.

@collinalexbell
Created November 12, 2016 19:52
Show Gist options
  • Save collinalexbell/a25560e5e72d58978f3dedbab407983e to your computer and use it in GitHub Desktop.
Save collinalexbell/a25560e5e72d58978f3dedbab407983e to your computer and use it in GitHub Desktop.
Regarding multi-dim indexing of numpy arrays
>>> 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