Suppose I have an array with 10 elements, e.g. a=np.arange(10)
. If I want to create another array with the 1st, 3rd, 5th, 7th, 9th, 10th elements of the original array, i.e. b=np.array([0,2,4,6,8,9])
, how can I do it efficiently?
thanks
Suppose I have an array with 10 elements, e.g. a=np.arange(10)
. If I want to create another array with the 1st, 3rd, 5th, 7th, 9th, 10th elements of the original array, i.e. b=np.array([0,2,4,6,8,9])
, how can I do it efficiently?
thanks
Index
a
with a list or array representing the desired indices. (Not1, 3, 5, 7, 9, 10
, because indexing starts from 0.) It's a bit confusing that the indices and the values are the same here, so have a different example:Note that this creates a copy, not a view. Also, note that this might not generalize to multiple axes the way you expect.