def expand(tup, ndim, name=None, expand_nonnum=False):
    if isinstance(tup, (tuple, list)) and len(tup) == ndim:
        return tup

    if isinstance(tup, _Number) or expand_nonnum:
        return (tup,) * ndim

    if not expand_nonnum:
        return tup

    raise ValueError("Bad number of dimensions{}: is {} but should be {}.".format((" for " + name) if name else "", len(tup), ndim))
dataset/ETHPy150Open lucasb-eyer/DeepFried2/DeepFried2/utils.py/expand/original