Numpy\'s ufuncs have a reduceat method which runs them over contiguous partitions within an array. So instead of writing:
import numpy as np
a =
Inspired by this question, ive added argmin/max functionality to the numpy_indexed package. Here is what the corresponding test looks like. Note that the keys may be in any order (and of any kind supported by npi):
def test_argmin():
keys = [2, 0, 0, 1, 1, 2, 2, 2, 2, 2]
values = [4, 5, 6, 8, 0, 9, 8, 5, 4, 9]
unique, amin = group_by(keys).argmin(values)
npt.assert_equal(unique, [0, 1, 2])
npt.assert_equal(amin, [1, 4, 0])