NumPy Fancy Array Indexing: Difference between revisions
Jump to navigation
Jump to search
(One intermediate revision by the same user not shown) | |||
Line 29: | Line 29: | ||
Using negative indices selects rows from the end. | Using negative indices selects rows from the end. | ||
Fancy indexing, unlike slicing, copies the data into a new array when assigning the result to a new variable. | |||
<font color=darkkhaki>TODO: https://learning.oreilly.com/library/view/python-for-data/9781098104023/ch04.html#:-:text=Fancy%20Indexing</font> |
Latest revision as of 17:17, 21 May 2024
Internal
Overview
Fancy indexing is a term adopted by NumPy to describe indexing using integer arrays.
In case of a bi-dimensional array, passing an unidimensional list containing row indices returns a bi-dimensional array where only the rows whose indices were provided are present, in the order in which the indices were specified in the selection array.
a = np.array([[10, 10], [20, 20], [30, 30], [40, 40]])
array([[10, 10], [20, 20], [30, 30], [40, 40]])
a[[3, 0]]
array([[40, 40], [10, 10]])
Using negative indices selects rows from the end.
Fancy indexing, unlike slicing, copies the data into a new array when assigning the result to a new variable.