x = array([0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1], dtype=np.bool)
print((x.itemsize, x.nbytes))
xp = np.packbits(x)
print(xp)
print((xp.itemsize, xp.nbytes))
How can I pack numpy bool arrays into a string of bits?