``````

In [1]:

import numpy as np

``````
``````

In [2]:

a = np.array([-100, -10, 0, 10, 100])
print(a)

``````
``````

[-100  -10    0   10  100]

``````
``````

In [3]:

print(np.signbit(a))

``````
``````

[ True  True False False False]

``````
``````

In [4]:

print(type(np.signbit(a)))

``````
``````

<class 'numpy.ndarray'>

``````
``````

In [5]:

print(np.signbit(a).dtype)

``````
``````

bool

``````
``````

In [6]:

print(np.signbit(-100))

``````
``````

True

``````
``````

In [7]:

print(a == 0)

``````
``````

[False False  True False False]

``````
``````

In [8]:

print(a > 0)

``````
``````

[False False False  True  True]

``````
``````

In [9]:

print(a >= 0)

``````
``````

[False False  True  True  True]

``````
``````

In [10]:

print(a < 0)

``````
``````

[ True  True False False False]

``````
``````

In [11]:

print(a <= 0)

``````
``````

[ True  True  True False False]

``````
``````

In [12]:

print(np.count_nonzero(np.signbit(a)))

``````
``````

2

``````
``````

In [13]:

print(~np.signbit(a))

``````
``````

[False False  True  True  True]

``````
``````

In [14]:

print(np.count_nonzero(~np.signbit(a)))

``````
``````

3

``````
``````

In [15]:

print(np.count_nonzero(a == 0))

``````
``````

1

``````
``````

In [16]:

print(np.count_nonzero(a < 0))

``````
``````

2

``````
``````

In [17]:

print(np.count_nonzero(a > 0))

``````
``````

2

``````
``````

In [18]:

a_special = np.array([0.0, -0.0, np.inf, -np.inf, np.nan])
print(a_special)

``````
``````

[  0.  -0.  inf -inf  nan]

``````
``````

In [19]:

print(np.signbit(a_special))

``````
``````

[False  True False  True False]

``````
``````

In [20]:

print(a_special == 0)

``````
``````

[ True  True False False False]

``````
``````

In [21]:

print(a_special < 0)

``````
``````

[False False False  True False]

/usr/local/lib/python3.7/site-packages/ipykernel_launcher.py:1: RuntimeWarning: invalid value encountered in less
"""Entry point for launching an IPython kernel.

``````
``````

In [22]:

print(a_special > 0)

``````
``````

[False False  True False False]

/usr/local/lib/python3.7/site-packages/ipykernel_launcher.py:1: RuntimeWarning: invalid value encountered in greater
"""Entry point for launching an IPython kernel.

``````
``````

In [23]:

a_complex = np.array([3 + 4j, -3 - 4j])
print(a_complex)

``````
``````

[ 3.+4.j -3.-4.j]

``````
``````

In [24]:

# print(np.signbit(a_complex))
# TypeError: ufunc 'signbit' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

``````
``````

In [25]:

print(np.abs(a_complex))

``````
``````

[5. 5.]

``````
``````

In [26]:

print(a_complex.real)

``````
``````

[ 3. -3.]

``````
``````

In [27]:

print(a_complex.imag)

``````
``````

[ 4. -4.]

``````
``````

In [28]:

print(np.signbit(a_complex.real))

``````
``````

[False  True]

``````
``````

In [29]:

print(a_complex.real < 0)

``````
``````

[False  True]

``````