In [1]:
import numpy as np

In [2]:
print(np.sign(100))


1

In [3]:
print(np.sign(-100))


-1

In [4]:
print(type(np.sign(100)))


<class 'numpy.int64'>

In [5]:
print(np.sign(1.23))


1.0

In [6]:
print(np.sign(-1.23))


-1.0

In [7]:
print(type(np.sign(1.23)))


<class 'numpy.float64'>

In [8]:
print(np.sign(0))


0

In [9]:
print(np.sign(0.0))


0.0

In [10]:
print(np.sign(-0.0))


0.0

In [11]:
print(np.sign(float('nan')))


nan

In [12]:
print(np.sign(float('-nan')))


nan

In [13]:
print(100 > 0)


True

In [14]:
print(True - False)


1

In [15]:
print(False - True)


-1

In [16]:
print(False - False)


0

In [17]:
def my_sign(x):
    return (x > 0) - (x < 0)

In [18]:
print(my_sign(100))


1

In [19]:
print(my_sign(-100))


-1

In [20]:
print(type(my_sign(100)))


<class 'int'>

In [21]:
print(my_sign(1.23))


1

In [22]:
print(my_sign(-1.23))


-1

In [23]:
print(type(my_sign(-1.23)))


<class 'int'>

In [24]:
print(my_sign(0))


0

In [25]:
print(my_sign(0.0))


0

In [26]:
print(my_sign(-0.0))


0

In [27]:
print(my_sign(float('nan')))


0

In [28]:
print(my_sign(float('-nan')))


0

In [29]:
# print(my_sign(3 + 4j))
# TypeError: '>' not supported between instances of 'complex' and 'int'

In [30]:
def my_sign_with_abs(x):
    return 0.0 if abs(x) == 0 else x / abs(x)

In [31]:
print(my_sign_with_abs(100))


1.0

In [32]:
print(my_sign_with_abs(-100))


-1.0

In [33]:
print(type(my_sign_with_abs(100)))


<class 'float'>

In [34]:
print(my_sign_with_abs(1.23))


1.0

In [35]:
print(my_sign_with_abs(-1.23))


-1.0

In [36]:
print(type(my_sign_with_abs(1.23)))


<class 'float'>

In [37]:
print(my_sign_with_abs(0))


0.0

In [38]:
print(my_sign_with_abs(0.0))


0.0

In [39]:
print(my_sign_with_abs(-0.0))


0.0

In [40]:
print(my_sign_with_abs(float('nan')))


nan

In [41]:
print(my_sign_with_abs(float('-nan')))


nan

In [42]:
print(abs(3 + 4j))


5.0

In [43]:
print(my_sign_with_abs(3 + 4j))


(0.6+0.8j)