def gen_even_slices(n, n_packs, n_samples=None):
    start = 0
    for pack_num in range(n_packs):
        this_n = n // n_packs
        if pack_num < n % n_packs:
            this_n += 1
        if this_n > 0:
            end = start + this_n
            if n_samples is not None:
                end = min(n_samples, end)
            yield slice(start, end, None)
            start = end
Generator to create n_packs slices going up to n.
dataset/ETHPy150Open trevorstephens/gplearn/gplearn/skutils/__init__.py/gen_even_slices