<br><br><div><span class="gmail_quote">On 1/24/07, <b class="gmail_sendername">Charles R Harris</b> <<a href="mailto:charlesr.harris@gmail.com">charlesr.harris@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;">
<br><br><div><div><span class="e" id="q_11054f1bf3a9d97b_1"><span class="gmail_quote">On 1/24/07, <b class="gmail_sendername">Robert Cimrman</b> <<a href="mailto:cimrman3@ntc.zcu.cz" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">
cimrman3@ntc.zcu.cz</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;">
Robert Kern wrote:<br>> Robert Cimrman wrote:<br>>> Or you could just call unique1d prior to your call to setmember1d - it<br>>> was meant to be used that way... you would not loose much speed that<br>>> way, IMHO.
<br>><br>> But that doesn't do what they want. They want a function that gives the mask<br>> against their original array of the elements that are in the other array. The<br>> result of<br>><br>>   setmember1d(unique1d(ar1), unique1d(ar2))
<br>></blockquote></span></div></div></blockquote><div><br><snip><br><br>For instance<br><br>I<span style="font-family: courier new,monospace;">n [7]: def countmembers(a1, a2) :</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">   ...:     a = sort(a2)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">   ...:     il = a.searchsorted(a1, side='l')
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">   ...:     ir = a.searchsorted(a1, side='r')</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
   ...:     return ir - il</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">   ...: </span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">In [8]: a2 = random.randint(0,10,(100,))</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
In [9]: a1 = arange(11)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"></span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
In [11]: a2 = random.randint(0,5,(100,))</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">In [12]: a1 = arange(10)</span>
<br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">In [13]: countmembers(a1,a2)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">Out[13]: array([16, 28, 16, 25, 15,  0,  0,  0,  0,  0])</span><br><br><br>The subtraction can be replaced by != to get a boolean mask.<br></div><br>Chuck<br><br></div><br>