irregular slicing/copying in numpy array
问题 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 回答1: a[[0, 2, 4, 6, 8, 9]] Index a with a list or array representing the desired indices. (Not 1, 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: >>> a =