[SciPy-user] Array selection help

Andrew Straw strawman@astraw....
Wed Feb 11 12:54:43 CST 2009


> def labelmeanfilter(arr1, arr2):
>     R = {}
>     [R.setdefault(row[0],[]).append(index) for index, row in
>                      enumerate(zip(arr1,arr2))]
> 


I think the following should produce a bit more speed (although I
haven't benchmarked it) because it avoids creating len(arr1) empty lists.

import collections

def labelmeanfilter(arr1, arr2):
    R = collections.defaultdict(list)
    [R[row[0]].append(index) for index, row in
                     enumerate(zip(arr1,arr2))]



More information about the SciPy-user mailing list