how to make a dtype for list of arrays in numpy python3+

221 views Asked by At

I have a 300x57 bytes array taken from serial port and shared then I intend to unpickle it directly into numpy array

so I make a dtype with 57 byte size

onebuffdtype = np.dtype(
        "b1, b1, f4, u4, u2, u1, f4, u4, u2, u1, f4, i4, i2, i1, f4, u4, u2, u1, f4, u4, u2, u1")

then if

shared_buff1.buf

is place where buffer is located

buff1_np = np.ndarray((300, 57,), dtype=onebuffdtype,
                          buffer=shared_buff1.buf)

but it says

TypeError: buffer is too small for requested array

1

There are 1 answers

0
Mad Physicist On BEST ANSWER

The shape of an array is the number of elements, not bytes it contains. If your elements are all 57 bytes in size, then a 300x57 byte buffer is just the right size to initialize an array of size 300:

buff1_np = np.ndarray(300, dtype=onebuffdtype, buffer=shared_buff1.buf)