2018-10-03 18:59:01 +00:00
|
|
|
# http://stackoverflow.com/questions/4651683/numpy-grouping-using-itertools-groupby-performance
|
|
|
|
# setup: import numpy as np ; N = 350000 ; values = np.array(np.random.randint(0,3298,size=N),dtype='u4') ; values.sort() # noqa
|
|
|
|
# run: grouping(values)
|
|
|
|
|
|
|
|
# pythran export grouping(uint32 [])
|
2018-04-05 22:07:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
def grouping(values):
|
|
|
|
import numpy as np
|
2020-06-28 18:24:40 +00:00
|
|
|
|
2018-04-05 22:07:33 +00:00
|
|
|
diff = np.concatenate(([1], np.diff(values)))
|
|
|
|
idx = np.concatenate((np.where(diff)[0], [len(values)]))
|
|
|
|
return values[idx[:-1]], np.diff(idx)
|