[Numpy-discussion] setmember1d: docstring vs. code
Charles R Harris
Sat Mar 10 16:16:35 CST 2007
On 3/10/07, Robert Kern <email@example.com> wrote:
> Jouni K. Seppänen wrote:
> > I think that either the docstring (and the book) should be corrected
> > to mention the assumption, or the code should be made to work in the
> > arbitrary case.
> This is the current docstring:
> In : setmember1d?
> Type: function
> Base Class: <type 'function'>
> Namespace: Interactive
> Definition: setmember1d(ar1, ar2)
> Return a boolean array of shape of ar1 containing True where the
> of ar1 are in ar2 and False otherwise.
> Use unique1d() to generate arrays with only unique elements to use as
> to this function.
> - `ar1` : array
> - `ar2` : array
> - `mask` : bool array
> The values ar1[mask] are in ar2.
> :See also:
> numpy.lib.arraysetops has a number of other functions for performing
> operations on arrays.
> > I would prefer the latter choice (but perhaps the
> > current code has some advantages).
> Well, it has the advantage of existing. If you have an implementation that
> just as efficient, but works for general arrays, I'd love to see it.
Well, the version I posted awhile back works for general arrays. How
efficient it is compared to the current version I haven't investigated. For
reference, here it is again.
def ismember(ar1, ar2) :
a = sort(ar2)
il = a.searchsorted(ar1, side='left')
ir = a.searchsorted(ar1, side='right')
return ir != il
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Numpy-discussion