Kim Hansen wrote: > Hi again > > It turned out not to be quite good enough as is, as it requires unique > values for both arrays. Whereas this is often true for the second > argument, it is never true for the first argument in my use case, and > I struggled with that for some time until i realized I could use > unique1d with the rever_index optional parameter set True > > def ismember(totest, members) > """ > A setmember1d, which works for totest arrays with duplicate values > """ > uniques_in_test, rev_idx = unique1d(totest, return_inverse=True) > uniques_in_members_mask = setmember1d(uniques_in_test, members) > # Use this instead is members is not unique > # uniques_in_members_mask = setmember1d(uniques_in_test, > unique1d(members)) > return uniques_in_members_mask[rev_idx] > > I saw someone else providing an alternative implementation of this, > which was longer and included a loop. I do not know which is the most > efficient one, but I understand this one better. > > -- Slaunger
I have added your implementation to http://projects.scipy.org/numpy/ticket/1036 - is it ok with you to add the function eventually into arraysetops.py, under the numpy (BSD) license? cheers, r. _______________________________________________ Numpy-discussion mailing list [email protected] http://projects.scipy.org/mailman/listinfo/numpy-discussion
