better way to do this in Numeric

John Hunter jdhunter at
Mon Aug 4 16:42:20 CEST 2003

I have a list of indices and want to assign the number of times an
index shows up in the list to an array with the count specified at the
index; ie,

    from Numeric import *

    a = zeros((10,), Int)
    ind = [1,1,4,4,4,4,7,7,9,9,9,9,9]

    for i in ind:
        a[i] += 1

I'm wondering if there is a way to use some combination of Numeric
array functions to make this speedy.

John Hunter

More information about the Python-list mailing list