NumPy Fancy Array Indexing
Jump to navigation
Jump to search
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.