I have a numpy array like ids = ([0,0,0,1,1,2,2,2,2,4,5,5,5]) and some other numpy arrays (say a and b) of the same length. I want to carry out some independent operations using slices of these arrays, with the slices defined as indexes that share the same (contiguous) set of ids. I.e. I want to define a set of slices like
slice_0 = 0:3
slice_1 = 3:5
slice_2 = 5:9
...
so that I can call a function f(a[slice_n],b[slice_n]) for each n in parallel. How do I construct the slices in numpy? If it helps, in R I would do it with something like tapply.
sliceobjects or tuples ofsliceobjects for multidimensional slicing (andEllipsisfor '...') or usingnp.s_.