def sliding_window(array, window, step=1, axis=0):
    """Generate chunks for encoding and labels.

    Args:
        array: Numpy array with the pileup counts
        window: Length of output chunks
        step: window minus chunk overlap
        axis: defaults to 0
    Returns:
        Iterator with chunks
    """
    chunk = [slice(None)] * array.ndim
    end = 0
    chunks = []
    for start in range(0, array.shape[axis] - window + 1, step):
        end = start + window
        chunk[axis] = slice(start, end)
        chunks.append(array[tuple(chunk)])
    if array.shape[axis] > end:
        start = array.shape[axis] - window
        chunk[axis] = slice(start, array.shape[axis])
        chunks.append(array[tuple(chunk)])
    return chunks