[Numpy-discussion] setmember1d memory leak?

Charles R Harris charlesr.harris at gmail.com
Thu Jan 25 03:45:34 CST 2007


On 1/24/07, Charles R Harris <charlesr.harris at gmail.com> wrote:
>
>
>
> On 1/24/07, Robert Cimrman <cimrman3 at ntc.zcu.cz> 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20070125/bda0e077/attachment.html 


More information about the Numpy-discussion mailing list