如何在numpy python3 +中为数组列表创建dtype

我有一个从串口获取并共享的300x57字节数组,然后打算将其直接释放为numpy数组

所以我创建了一个57字节大小的dtype

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

然后,如果

shared_buff1.buf

是缓冲区所在的地方

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

但它说

  

TypeError:缓冲区对于请求的数组而言太小

syiaeb7420 回答:如何在numpy python3 +中为数组列表创建dtype

数组的形状是元素的数量,而不是它包含的字节数。如果您的元素都是57字节大小,则300x57字节缓冲区恰好是初始化大小为300的数组的正确大小:

buff1_np = np.ndarray(300,dtype=onebuffdtype,buffer=shared_buff1.buf)
本文链接:https://www.f2er.com/3135529.html

大家都在问