def simplify(ind):
    """Simplify an index list into a slice, if possible
    does *not* return single integer indices, since that screws up the dimensions
    when applying these slices to numpy arrays."""
    assert hasattr(ind, '__len__'), 'not an array of indices'
    if len(ind) == 1:
        ind = int(ind[0])
        return slice(ind, ind + 1, 1)
    import numpy as np
    delt = np.unique(np.diff(ind))
    if len(delt) != 1 or delt == 0:
        return ind
    delt = int(delt[0])
    start, stop, step = int(ind[0]), int(ind[-1]) + delt, delt
    if stop < 0:
        stop = None
    return slice(start, stop, step)
