On Mon, Feb 9, 2009 at 6:02 AM, Neil <[email protected]> wrote: > >> > I have two integer arrays of different shape, e.g. >> > >> > >>> a >> > >> > array([ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) >> > >> > >>> b >> > >> > array([ 3, 4, 5, 6, 7, 8, 9, 10]) >> > >> > How can I extract the values that belong to the array a >> > exclusively i.e. array([1,2]) ? >> > > You could also use numpy.setmember1d to get a boolean mask that selects > the values: > > In [21]: a = np.array([ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) > In [22]: b = np.array([ 3, 4, 5, 6, 7, 8, 9, 10]) > In [23]: ismember = np.setmember1d(a,b) > In [24]: a[~ismember] > Out[24]: array([1, 2]) > > > Neil > > > _______________________________________________ > Numpy-discussion mailing list > [email protected] > http://projects.scipy.org/mailman/listinfo/numpy-discussion >
there's also np.setdiff1d() which does the above in a single line. -brent _______________________________________________ Numpy-discussion mailing list [email protected] http://projects.scipy.org/mailman/listinfo/numpy-discussion
