A simply example of numpy indexing:
In: a = numpy.arange(10)
In: sel_id = numpy.arange(5)
In: a[sel_id]
Out: array([0,1,2,3,4])
How do I return the rest of the array that are not indexed by sel_id? What I can think of is:
In: numpy.array([x for x in a if x not in a[id]])
out: array([5,6,7,8,9])
Is there any easier way?
For this simple 1D case, I’d actually use a boolean mask:
Now you can get your values:
Note that
a[mask]doesn’t necessarily yield the same thing asa[include_index]since the order ofinclude_indexmatters for the output in that scenario (it should be roughly equivalent toa[sorted(include_index)]). However, since the order of your excluded items isn’t well defined, this should work Ok.EDIT
A better way to create the mask is:
(thanks to seberg).