In [1]:
import numpy as np
In [2]:
print(np.sign(100))
In [3]:
print(np.sign(-100))
In [4]:
print(type(np.sign(100)))
In [5]:
print(np.sign(1.23))
In [6]:
print(np.sign(-1.23))
In [7]:
print(type(np.sign(1.23)))
In [8]:
print(np.sign(0))
In [9]:
print(np.sign(0.0))
In [10]:
print(np.sign(-0.0))
In [11]:
print(np.sign(float('nan')))
In [12]:
print(np.sign(float('-nan')))
In [13]:
print(100 > 0)
In [14]:
print(True - False)
In [15]:
print(False - True)
In [16]:
print(False - False)
In [17]:
def my_sign(x):
return (x > 0) - (x < 0)
In [18]:
print(my_sign(100))
In [19]:
print(my_sign(-100))
In [20]:
print(type(my_sign(100)))
In [21]:
print(my_sign(1.23))
In [22]:
print(my_sign(-1.23))
In [23]:
print(type(my_sign(-1.23)))
In [24]:
print(my_sign(0))
In [25]:
print(my_sign(0.0))
In [26]:
print(my_sign(-0.0))
In [27]:
print(my_sign(float('nan')))
In [28]:
print(my_sign(float('-nan')))
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))
In [32]:
print(my_sign_with_abs(-100))
In [33]:
print(type(my_sign_with_abs(100)))
In [34]:
print(my_sign_with_abs(1.23))
In [35]:
print(my_sign_with_abs(-1.23))
In [36]:
print(type(my_sign_with_abs(1.23)))
In [37]:
print(my_sign_with_abs(0))
In [38]:
print(my_sign_with_abs(0.0))
In [39]:
print(my_sign_with_abs(-0.0))
In [40]:
print(my_sign_with_abs(float('nan')))
In [41]:
print(my_sign_with_abs(float('-nan')))
In [42]:
print(abs(3 + 4j))
In [43]:
print(my_sign_with_abs(3 + 4j))