def sub(a,b):
    """Subtract a vector b from a, or subtract a scalar"""
    if hasattr(b,'__iter__'):
        if len(a)!=len(b):
            raise RuntimeError('Vector dimensions not equal')
        return [ai-bi for ai,bi in zip(a,b)]
    else:
        return [ai-b for ai in a]