I have a binary file and I wonder how I can read it using numpy. The format of the data is 10 characters of string followed by 100 floats (stored using 4 characters each). I know the following snippet with struct module can solve this, but for large files the struct code is too time-consuming.
f = open(file, 'rb')
while True:
tag = f.read(10)
if tag== '': break
b = []
for i in range(100):
b.append(struct.unpack('f', f.read(4)))
yield tag, b
I'm a little confused with the numpy.fromfile, it seems this can meet my requirement.