def sign(x):
    y = np.ones_like(x)
y[np.asarray(x) < 0] = -1
if isinstance(x, np.ndarray):
    return y
else:
    return type(x)(y)
A python function that accepts as an argument either a scalar or a numpy array