In [1]:
import numpy as np
In [2]:
print(np.__version__)
In [3]:
a_int = np.array([0, 1, 3]) # [0b00 0b01 0b11]
b_int = np.array([1, 0, 2]) # [0b01 0b00 0b10]
In [4]:
print(a_int.dtype)
In [5]:
print(b_int.dtype)
In [6]:
print(a_int & b_int)
In [7]:
print(a_int | b_int)
In [8]:
print(a_int ^ b_int)
In [9]:
print(~a_int)
In [10]:
print(a_int << b_int)
In [11]:
print(a_int >> b_int)
In [12]:
print(np.bitwise_and(a_int, b_int))
In [13]:
print(np.bitwise_or(a_int, b_int))
In [14]:
print(np.bitwise_xor(a_int, b_int))
In [15]:
print(np.bitwise_not(a_int))
In [16]:
print(np.invert(a_int))
In [17]:
print(~a_int)
In [18]:
print(-(a_int + 1))
In [19]:
a_uint8 = np.array([0, 1, 3], dtype=np.uint8)
In [20]:
print(~a_uint8)
In [21]:
a_uint16 = np.array([0, 1, 3], dtype=np.uint16)
In [22]:
print(~a_uint16)
In [23]:
c_int_2d = np.arange(6).reshape(2, 3)
print(c_int_2d)
In [24]:
print(c_int_2d & a_int)
In [25]:
print(np.bitwise_and(c_int_2d, a_int))
In [26]:
print(c_int_2d & 2)
In [27]:
print(np.bitwise_and(c_int_2d, 2))
In [28]:
d_float = np.array([0, 1, 3], dtype=float)
In [29]:
# print(a_int & d_float)
# TypeError: ufunc 'bitwise_and' 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 [30]:
# print(~d_float)
# TypeError: ufunc 'invert' 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 [31]:
# print(np.bitwise_and(a_int, d_float))
# TypeError: ufunc 'bitwise_and' 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 [32]:
# print(np.bitwise_not(d_float))
# TypeError: ufunc 'invert' 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 [33]:
e_bool = np.array([True, False, True])
In [34]:
print(a_int & e_bool)
In [35]:
print((a_int & e_bool).dtype)
In [36]:
print(np.bitwise_and(a_int, e_bool))
In [37]:
print(np.bitwise_and(a_int, e_bool).dtype)
In [38]:
print(~e_bool)
In [39]:
print(np.logical_not(e_bool))
In [40]:
print(np.bitwise_not(e_bool))
In [41]:
print(np.invert(e_bool))