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
sign
abs
si
You dont need one, you can just use:
if not number == 0: sig = number/abs(number) else: sig = 0
Or create a function as described by others:
sign = lambda x: bool(x > 0) - bool(x < 0) def sign(x): return bool(x > 0) - bool(x < 0)