0

我必须从文件中获取一些字节作为数据。但是要读取的字节数会根据某些字节而有所不同。这是一个例子。数据格式为 128 字节。前 64 个字节类似。所以没问题。但接下来的 64 个字节是可变的。

Let us say 65th byte is "a", then 
 66 + 67 bytes = var x
68+69+70+71 bytes = var y

In case 65th byte is "b" , then 
66th byte : var z
67th byte: var k
68+69 =var o
70+71+72+73 = var m
dtype = [('var1',np.uint32),('var2',np.uint16).......]
with open(filename,'rb') as fh:
    data = np.fromfile(fh,dtype)

是否可以使用 numpy 和 dtype 获取此类数据。还是我需要运行一个 for 循环?循环会很昂贵,因为这是一个巨大的文件。有什么想法可以解决吗?

4

0 回答 0