【发布时间】:2019-05-14 00:30:06
【问题描述】:
我有一个一维整数数组,通过
从二进制文件中读取data = np.fromfile(file.dat, 'u1')
数据返回的地方
array([242, 255, 101, 0, 124, 0, 86, 0, 33, 0,
112, 0, 32, 1, 74, 1, 195, 0, 16, 0], dtype=uint8)
系列中的0's 表示用于高于或低于标准 256 的值的额外位。例如,索引 0 处的 244 应为 -14,并由 255(或 256)-242 表示。相反,索引 13 处的值 - 读取为 32 实际上是 256 + 32 或 288。我试图让上面的数组看起来像 --
[-14, 101, 124, 86, 33, 112, 288, 330, 195, 16]
如果找到值 1 或 255,我想我想要使用索引和值来评估前一个值的东西。
我从下面开始,但在一天结束时丢失了线程。
for i, a in enumerate(data):
if a == 255:
neg = i,a
如果有人可以推荐一种更好的方法来处理二进制值,我也愿意学习。帮助表示赞赏!
【问题讨论】:
-
lost the thread at the end of the day.是什么意思? -
哈,累的委婉说法
标签: python arrays list numpy binary