[SciPy-user] Array selection help
Andrew Straw
strawman at astraw.com
Wed Feb 11 13:54:43 EST 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