[Numpy-discussion] Fancier indexing

Kevin Jacobs <jacobs@bioinformed.com> bioinformed@gmail....
Thu May 22 10:59:37 CDT 2008


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 code, 'items' contain up to a million values and this loop will
be in a performance critical area of code.  If there is no simple solution,
I can trivially code this using the C-API.

Thanks,
-Kevin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20080522/e536a60f/attachment.html 


More information about the Numpy-discussion mailing list