[SciPy-user] Array selection help

josef.pktd@gmai... josef.pktd@gmai...
Wed Feb 11 12:46:14 CST 2009

sorry, cut and paste error, the test function used globals, correction below.

You can speed up a little bit more using itertools.izip instead of
zip. (labelmeanfilter 0.377629000334)

def test_labelmeanfilter(arr1, arr2):
    arr3b = labelmeanfilter(arr1, arr2)

    labelsunique = np.unique(arr1)
    labelmeans = ndimage.mean(arr2, labels=arr1, index=labelsunique)
    labmeandict = dict(zip(labelsunique,labelmeans))
    for orig,means in zip(arr1,arr3b):
        assert_array_equal(means, labmeandict[orig], repr(orig))

More information about the SciPy-user mailing list