diff options
author | Paul Rougieux <paul.rougieux@gmail.com> | 2020-04-20 22:41:30 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-20 15:41:30 -0500 |
commit | 9eb7560e77c43af561f5242cf30df6b1d7442e83 (patch) | |
tree | 2ff34e2b8b00d7c3914fb7ac50b924912dda024e /numpy/doc/indexing.py | |
parent | 2f790d8768095a7c237794eaff31b8ae4a0411f9 (diff) | |
download | numpy-9eb7560e77c43af561f5242cf30df6b1d7442e83.tar.gz |
DOC: Clarify docs on mixed advanced indexing and slicing (gh-15891)
It was not clear how to reproduce the slice example with multi dimensional array indexing. I hope the additional example clarifies the equivalence between slice and multi array for new users.
Co-Authored-By: Eric Wieser <wieser.eric@gmail.com>
Co-Authored-By: Anirudh Subramanian <anirudh2290@apache.org>
Diffstat (limited to 'numpy/doc/indexing.py')
-rw-r--r-- | numpy/doc/indexing.py | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/numpy/doc/indexing.py b/numpy/doc/indexing.py index 6b15a7a9e..c7dda2790 100644 --- a/numpy/doc/indexing.py +++ b/numpy/doc/indexing.py @@ -285,14 +285,23 @@ Combining index arrays with slices Index arrays may be combined with slices. For example: :: - >>> y[np.array([0,2,4]),1:3] + >>> y[np.array([0, 2, 4]), 1:3] array([[ 1, 2], [15, 16], [29, 30]]) -In effect, the slice is converted to an index array -np.array([[1,2]]) (shape (1,2)) that is broadcast with the index array -to produce a resultant array of shape (3,2). +In effect, the slice and index array operation are independent. +The slice operation extracts columns with index 1 and 2, +(i.e. the 2nd and 3rd columns), +followed by the index array operation which extracts rows with +index 0, 2 and 4 (i.e the first, third and fifth rows). + +This is equivalent to:: + + >>> y[:, 1:3][np.array([0, 2, 4]), :] + array([[ 1, 2], + [15, 16], + [29, 30]]) Likewise, slicing can be combined with broadcasted boolean indices: :: |