def slices_from_chunks(chunks):
 cumdims = [list(accumulate(add, ((0,) + bds[:(-1)]))) for bds in chunks]
 shapes = product(*chunks)
 starts = product(*cumdims)
 return [tuple((slice(s, (s + dim)) for (s, dim) in zip(start, shape))) for (start, shape) in zip(starts, shapes)]

def slices_from_chunks ( chunks ) : cumdims = [ list ( accumulate ( add , ( ( 0 , ) + bds [ : ( - 1 ) ] ) ) ) for bds in chunks ] shapes = product ( * chunks ) starts = product ( * cumdims ) return [ tuple ( ( slice ( s , ( s + dim ) ) for ( s , dim ) in zip ( start , shape ) ) ) for ( start , shape ) in zip ( starts , shapes ) ]
translate chunks tuple to a set of slices in product order .