def expand(ind, upper_bound):
    """Expand a slice or integer into an explicit array of indices"""
    import numpy as np
    if hasattr(ind, '__len__'):
        return np.array(ind, dtype='int32')
    if isinstance(ind, int):
        return np.array([ind], dtype='int32')
    assert isinstance(ind, slice), 'unknown slicing mechanism - ' + repr(ind)
    start, stop, step = ind.start, ind.stop, ind.step
    if step is None:
        step = 1
    assert step != 0
    if start is None:
        if step > 0:
            start = 0
        else:
            start = upper_bound - 1
    if start < 0:
        start += upper_bound
    if stop is None:
        if step > 0:
            stop = upper_bound
        else:
            stop = -1
    elif stop < 0:
        stop += upper_bound
    return np.arange(start, stop, step, dtype='int32')
