On 3/10/07, Robert Kern <[EMAIL PROTECTED]> 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 [2]: setmember1d?
Type:           function
Base Class:     <type 'function'>
Namespace:      Interactive
File:
/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/numpy-
1.0.2.dev3569-py2.5-macosx-10.3-fat.egg/numpy/lib/arraysetops.py
Definition:     setmember1d(ar1, ar2)
Docstring:
    Return a boolean array of shape of ar1 containing True where the
elements
    of ar1 are in ar2 and False otherwise.

    Use unique1d() to generate arrays with only unique elements to use as
inputs
    to this function.

    :Parameters:
      - `ar1` : array
      - `ar2` : array

    :Returns:
      - `mask` : bool array
        The values ar1[mask] are in ar2.

    :See also:
      numpy.lib.arraysetops has a number of other functions for performing
set
      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
is
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


Chuck
_______________________________________________
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to