I can\'t understand why Python doesn\'t have a sign function. It has an abs builtin (which I consider sign\'s sister), but no si
numpy has a sign function, and gives you a bonus of other functions as well. So:
import numpy as np
x = np.sign(y)
Just be careful that the result is a numpy.float64:
>>> type(np.sign(1.0))
For things like json, this matters, as json does not know how to serialize numpy.float64 types. In that case, you could do:
float(np.sign(y))
to get a regular float.