def index_to_slices(index):
if len(index)==<NUM_LIT:0>:<EOL><INDENT>return[]<EOL><DEDENT>ind = np.asarray(index,dtype=np.int)<EOL>ret = [[] for i in range(ind.max()+<NUM_LIT:1>)]<EOL>ind_ = np.hstack((ind,ind[<NUM_LIT:0>]+ind[-<NUM_LIT:1>]+<NUM_LIT:1>))<EOL>switchpoints = np.nonzero(ind_ - np.roll(ind_,+<NUM_LIT:1>))[<NUM_LIT:0>]<EOL>[ret[ind_i].append(slice(*indexes_i)) for ind_i,indexes_i in zip(ind[switchpoints[:-<NUM_LIT:1>]],zip(switchpoints,switchpoints[<NUM_LIT:1>:]))]<EOL>return ret<EOL>
take a numpy array of integers (index) and return a  nested list of slices such that the slices describe the start, stop points for each integer in the index.

e.g.
>>> index = np.asarray([0,0,0,1,1,1,2,2,2])
returns
>>> [[slice(0,3,None)],[slice(3,6,None)],[slice(6,9,None)]]

or, a more complicated example
>>> index = np.asarray([0,0,1,1,0,2,2,2,1,1])
returns
>>> [[slice(0,2,None),slice(4,5,None)],[slice(2,4,None),slice(8,10,None)],[slice(5,8,None)]]