Using numpy pack/unpackbits, they are your best friends.
Examples-------->>> a = np.array([[2], [7], [23]], dtype=np.uint8)>>> aarray([[ 2], [ 7], [23]], dtype=uint8)>>> b = np.unpackbits(a, axis=1)>>> barray([[0, 0, 0, 0, 0, 0, 1, 0], [0, 0, 0, 0, 0, 1, 1, 1], [0, 0, 0, 1, 0, 1, 1, 1]], dtype=uint8)