<br><br><div><span class="gmail_quote">On 3/10/07, <b class="gmail_sendername">Robert Kern</b> <<a href="mailto:robert.kern@gmail.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">robert.kern@gmail.com
</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Jouni K. Seppänen wrote:<br><br>> I think that either the docstring (and the book) should be corrected<br>> to mention the assumption, or the code should be made to work in the<br>> arbitrary case.<br><br>This is the current docstring:
<br><br>In [2]: setmember1d?<br>Type:           function<br>Base Class:     <type 'function'><br>Namespace:      Interactive<br>File:<br>/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<br>Definition:     setmember1d(ar1, ar2)<br>Docstring:<br>    Return a boolean array of shape of ar1 containing True where the elements<br>    of ar1 are in ar2 and False otherwise.
<br><br>    Use unique1d() to generate arrays with only unique elements to use as inputs<br>    to this function.<br><br>    :Parameters:<br>      - `ar1` : array<br>      - `ar2` : array<br><br>    :Returns:<br>      - `mask` : bool array
<br>        The values ar1[mask] are in ar2.<br><br>    :See also:<br>      numpy.lib.arraysetops has a number of other functions for performing set<br>      operations on arrays.<br><br>> I would prefer the latter choice (but perhaps the
<br>> current code has some advantages).<br><br>Well, it has the advantage of existing. If you have an implementation that is<br>just as efficient, but works for general arrays, I'd love to see it.</blockquote><div>

<br>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.<br><br><span style="font-family: courier new,monospace;">
def ismember(ar1, ar2) :</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
    a = sort(ar2)<br>    il = a.<span id="st" name="st" class="st">searchsorted</span>(ar1, side='left')<br>    ir = a.<span id="st" name="st" class="st">searchsorted</span>(ar1, side='right')<br style="font-family: courier new,monospace;">
</span><span style="font-family: courier new,monospace;">
    return ir != il</span><br><br></div><br>Chuck<br><br></div><br>