First page Back Continue Last page Overview Graphics

Indexing with an Array of integers

>>> a = np.array([34, 24, 89, 66, 45, 43, 46, 99, 102, 13])

>>> a[[1,2,5,8]]

array([ 24, 89, 43, 102])

>>> # indices can be repeated:

...

>>> a[[1,2,5,8,2,1]]

array([ 24, 89, 43, 102, 89, 24])

>>> # new values can be assigned with this method:

...

>>> a[[1,2,5,8]] = 42

>>> a

array([34, 42, 42, 66, 45, 42, 46, 99, 42, 13])