better way to do this in Numeric

John Hunter jdhunter at ace.bsd.uchicago.edu
Mon Aug 4 10:42:20 EDT 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.

Thanks,
John Hunter





More information about the Python-list mailing list