I have declared a numpy ndarray containing a single unsigned integer:
import numpy as np
foo=np.array([3600000],dtype='uint32')
I would like to store this array into a 4 bytes sequence. I have already tested a few options, such as the struct.pack() and struct.pack_into() methods, to no avail. I have also tried the numpy.ndarray.tobytes() method, which converts the content of my array into a bytes object:
bar=np.ndarray.tobytes(foo)
Alas, the ouput byte object has a length of 4 bits! How can I control the number of bits of my output bytes sequence?
Many thanks for your help!