Re: [Numpy-discussion] Fancier indexing

2008-05-22 Thread Keith Goodman
On Thu, May 22, 2008 at 9:22 AM, Robin <[EMAIL PROTECTED]> wrote: > On Thu, May 22, 2008 at 4:59 PM, Kevin Jacobs <[EMAIL PROTECTED]> > <[EMAIL PROTECTED]> wrote: >> After poking around for a bit, I was wondering if there was a faster method >> for the following: >> >> # Array of index values 0..n

Re: [Numpy-discussion] Fancier indexing

2008-05-22 Thread Robin
On Thu, May 22, 2008 at 4:59 PM, Kevin Jacobs <[EMAIL PROTECTED]> <[EMAIL PROTECTED]> wrote: > After poking around for a bit, I was wondering if there was a faster method > for the following: > > # Array of index values 0..n > items = numpy.array([0,3,2,1,4,2],dtype=int) > > # Count the number of o

Re: [Numpy-discussion] Fancier indexing

2008-05-22 Thread Keith Goodman
On Thu, May 22, 2008 at 9:15 AM, Keith Goodman <[EMAIL PROTECTED]> wrote: > On Thu, May 22, 2008 at 9:08 AM, Keith Goodman <[EMAIL PROTECTED]> wrote: >> On Thu, May 22, 2008 at 8:59 AM, Kevin Jacobs <[EMAIL PROTECTED]> >> <[EMAIL PROTECTED]> wrote: >>> After poking around for a bit, I was wondering

Re: [Numpy-discussion] Fancier indexing

2008-05-22 Thread Mark Miller
You're just trying to do this...correct? >>> import numpy >>> items = numpy.array([0,3,2,1,4,2],dtype=int) >>> unique = numpy.unique(items) >>> unique array([0, 1, 2, 3, 4]) >>> counts=numpy.histogram(items,unique) >>> counts (array([1, 1, 2, 1, 1]), array([0, 1, 2, 3, 4])) >>> counts[0] array([1,

Re: [Numpy-discussion] Fancier indexing

2008-05-22 Thread Keith Goodman
On Thu, May 22, 2008 at 9:08 AM, Keith Goodman <[EMAIL PROTECTED]> wrote: > On Thu, May 22, 2008 at 8:59 AM, Kevin Jacobs <[EMAIL PROTECTED]> > <[EMAIL PROTECTED]> wrote: >> After poking around for a bit, I was wondering if there was a faster method >> for the following: >> >> # Array of index valu

Re: [Numpy-discussion] Fancier indexing

2008-05-22 Thread Kevin Jacobs <[EMAIL PROTECTED]>
On Thu, May 22, 2008 at 12:08 PM, Keith Goodman <[EMAIL PROTECTED]> wrote: > How big is n? If it is much smaller than a million then loop over that > instead. > n is always relatively small, but I'd rather not do: for i in range(n): counts[i] = (items==i).sum() If that was the best alternativ

Re: [Numpy-discussion] Fancier indexing

2008-05-22 Thread Keith Goodman
On Thu, May 22, 2008 at 8:59 AM, Kevin Jacobs <[EMAIL PROTECTED]> <[EMAIL PROTECTED]> wrote: > After poking around for a bit, I was wondering if there was a faster method > for the following: > > # Array of index values 0..n > items = numpy.array([0,3,2,1,4,2],dtype=int) > > # Count the number of o

[Numpy-discussion] Fancier indexing

2008-05-22 Thread Kevin Jacobs <[EMAIL PROTECTED]>
After poking around for a bit, I was wondering if there was a faster method for the following: # Array of index values 0..n items = numpy.array([0,3,2,1,4,2],dtype=int) # Count the number of occurrences of each index counts = numpy.zeros(5, dtype=int) for i in items: counts[i] += 1 In my real