On 1/24/07, Charles R Harris <[EMAIL PROTECTED]> wrote:



On 1/24/07, Robert Cimrman <[EMAIL PROTECTED]> wrote:
>
> Robert Kern wrote:
> > Robert Cimrman wrote:
> >> Or you could just call unique1d prior to your call to setmember1d -
> it
> >> was meant to be used that way... you would not loose much speed that
> >> way, IMHO.
> >
> > But that doesn't do what they want. They want a function that gives
> the mask
> > against their original array of the elements that are in the other
> array. The
> > result of
> >
> >   setmember1d(unique1d(ar1), unique1d(ar2))
> >


<snip>

For instance

In [7]: def countmembers(a1, a2) :
  ...:     a = sort(a2)
  ...:     il = a.searchsorted(a1, side='l')
  ...:     ir = a.searchsorted(a1, side='r')
  ...:     return ir - il
  ...:

In [8]: a2 = random.randint(0,10,(100,))

In [9]: a1 = arange(11)

In [11]: a2 = random.randint(0,5,(100,))

In [12]: a1 = arange(10)

In [13]: countmembers(a1,a2)
Out[13]: array([16, 28, 16, 25, 15,  0,  0,  0,  0,  0])


The subtraction can be replaced by != to get a boolean mask.

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

Reply via email to