【发布时间】:2019-08-17 19:26:02
【问题描述】:
我使用这种语法来转换字节数组数据字(每个样本 2 个字节):
data = numpy.fromstring(dataword, dtype=numpy.int16)
Python 3.7 中的相同指令返回错误:
TypeError: fromstring() argument 1 must be read-only bytes-like object, not memoryview
dataword = scope.ReadBinary(rlen-4) #dataword is a byte array, each 2 byte is an integer
data = numpy.fromstring(dataword, dtype=numpy.int16)# data is the int16 array
这是 Python 2.7.14 中data 的内容:
[-1.41601562 -1.42382812 -1.42578125 ..., 1.66992188 1.65234375 1.671875 ]
我希望在 Python 3.7 中获得相同的结果。
我应该如何在 3.7 中使用 numpy.fromstring()?
【问题讨论】:
-
什么是
scope? -
scope 是一个 activex 对象,需要从仪器接收二进制向量。在 python 2.7.14 中,数据字被定义为二进制数组:缓冲区:��P��������0����@�p��p����...... ..
-
python 3.7:在 LIclipse 的变量选项卡中,我可以看到 dataword 被定义为 memoryview:
标签: python arrays python-2.7 numpy python-3.7