I have a numpy array of dimensions Nx8, with dtyp=boolean I want to convert it into a numpy 1-d array where each row is turned into a byte, by bin2dec
x = array([[ True, True, False, False, True, True, False, False],
[ False, False, False, False, True, True, False, False],
[ True, False, False, False, False, False, False, False]], dtype=bool)
I'd like the output to be:
y = array([204 ,12, 128], dtype=uint8)
>>> np.packbits(np.uint8(x))
array([204, 12, 128], dtype=uint8)
How that?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With