如何选择NumPy数组中除索引序列以外的所有元素
问题描述:
说我有一些长数组和一个索引列表.我该如何选择除那些索引以外的所有内容?我找到了一个解决方案,但它并不优雅:
Say I have some long array and a list of indices. How can I select everything except those indices? I found a solution but it is not elegant:
import numpy as np
x = np.array([0,10,20,30,40,50,60])
exclude = [1, 3, 5]
print x[list(set(range(len(x))) - set(exclude))]