How to select all elements in a NumPy array except for a sequence of indices

Viewed 63675

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))]
4 Answers
Related