How to get specific values from numpy array by using negative indexes in Python

1 Answer

0 votes
import numpy as np

sequence = np.arange(1, 30, 2) 
print(sequence)

arr = sequence[np.array([2, -2, 4, -4])]
print(arr)


'''
run:

[ 1  3  5  7  9 11 13 15 17 19 21 23 25 27 29]
[ 5 27  9 23] 

'''

 



answered Jan 24, 2019 by avibootz
...