How to select all elements in a NumPy array except for a sequence of indices
This is what numpy.delete
does. (It doesn't modify the input array, so you don't have to worry about that.)
In [4]: np.delete(x, exclude)
Out[4]: array([ 0, 20, 40, 60])
np.delete
does various things depending what you give it, but in a case like this it uses a mask like:
In [604]: mask = np.ones(x.shape, bool)
In [605]: mask[exclude] = False
In [606]: mask
Out[606]: array([ True, False, True, False, True, False, True], dtype=bool)
In [607]: x[mask]
Out[607]: array([ 0, 20, 40, 60])