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))
>
> is a mask against
>
>   unique1d(ar1)
>
> not
>
>   ar1
>
> as they want.

I see. I was thinking in terms of 'set member' - in set one assumes
unique elements. A good name for this kind of function would be
'arraymember'.

Naive pseudo-implementation:

import numpy as nm
def arraymember1d( ar1, ar2 ):

    ar = ar2.copy().sort()
    indx = findsorted( ar2, ar1 )
    flag = nm.zeros( ar1.shape, dtype = nm.bool )
    flag[indx] = True

    return flag

Note that nm.searchsorted cannot be used here - a new function
('findsorted'?) would be needed.


Maybe something  like

countelements(ar1, ar2) :
   a = sort(ar2)
   il = a.searchsorted(ar1, side='left')
   ir = a.searchsorted(ar1, side='right')
   return ir - il

which returns an array containing the number of times the corresponding
element of ar1 is contained in ar2.


Chuck
_______________________________________________
Numpy-discussion mailing list
[email protected]
http://projects.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to