uint8 little endian array to uint16 big endian
问题 In Python2.7, from an USB bulk transfer I get an image frame from a camera: frame = dev.read(0x81, 0x2B6B0, 1000) I know that one frame is 342x260 = 88920 pixels little endian, because that I read 2x88920 = 177840 (0x2B6B0) from the bulk transfer. How can I convert the content of the frame array that is typecode=B into an uint16 big endian array? 回答1: Something like this should do the trick: frame_short_swapped = array.array('H', ((j << 8) | i for (i,j) in zip(frame[::2], frame[1::2]))) It