I have a binary file that contains 32-bit floats. I need to be able to read certain sections of the file into a list or other array-like structure. In other words, I need to read a specific number of bytes (specific number of float32s) at a time into my data structure, then use seek() to seek to another point in the file and do the same thing again.
In pseudocode:
new_list = []
with open('my_file.data', 'rb') as file_in:
for idx, offset in enumerate(offset_values):
# seek in the file by the offset
# read n float32 values into new_list[idx][:]
What is the most efficient/least confusing way to do this?
numpy.memmapto memory-map the file as a numpy array with dtypenumpy.float32.