[SciPy-user] Array selection help

josef.pktd@gmai... josef.pktd@gmai...
Wed Feb 11 13:26:04 CST 2009


labelmeanfilter 0.387612196522

labelmeanfilter1 0.0931486264316  #new version

from itertools import izip

def labelmeanfilter1(arr1, arr2):
    labelsunique = np.unique(arr1)
    labelmeans = ndimage.mean(arr2, labels=arr1, index=labelsunique)
    labmeandict = dict(izip(labelsunique,labelmeans))
    arr3 = np.array([labmeandict[orig] for orig in arr1])
    return arr3

arr3_0 = labelmeanfilter(arr1, arr2)
arr3_1 = labelmeanfilter1(arr1, arr2)
>>> np.all(arr3_1 == arr3_0)
True
>>> arr3_1.shape
(100000,)


I'm finished playing, it's simple and obvious.
Josef


More information about the SciPy-user mailing list