I'm trying to read and loading binary data from a 32-bit binary file (Little endian) into a numpy array but I keep on getting a list of nan's. For Computational goods, I was trying to read it in by chunks.
Some previous Posts I looked at:
- Reading an entire binary file into Python
- Reading an entire binary file into Python
- Reading a 32 bit floating point binary data file (little endian)
- How do I build a numpy array from a generator?
- Reading binary file and looping over each byte
This is one sample code I used:
from pathlib import Path
from functools import partial
from io import DEFAULT_BUFFER_SIZE
def file_byte_iterator(path):
"""given a path, return an iterator over the file
that lazily loads the file
"""
path = Path(path)
with path.open('rb') as file:
reader = partial(file.read1, DEFAULT_BUFFER_SIZE)
file_iterator = iter(reader, bytes())
for chunk in file_iterator:
for byte in chunk:
yield byte