'Numpy unpackbits type error when trying to convert bytes to bits

To get bits from bytes:

bytes = bytes([0x13, 0x00, 0x00, 0x00, 0x08, 0x00])
bits = numpy.unpackbits(bytes)  

throws this error:
TypeError: Expected an input array of unsigned byte data type
but if I get bytes in this way it works:

bytes = numpy.fromfile(filename, dtype="uint8")

How to solve this error, thanks.



Solution 1:[1]

bytes should be unsigned array, why not use a numpy unsigned?

bytearray = numpy.array([0x13, 0x00, 0x00, 0x00, 0x08, 0x00],dtype=numpy.uint8)
bits = numpy.unpackbits(bytearray)  

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Okapi575