1

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:

  1. Reading an entire binary file into Python
  2. Reading an entire binary file into Python
  3. Reading a 32 bit floating point binary data file (little endian)
  4. How do I build a numpy array from a generator?
  5. 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
martineau
  • 119,623
  • 25
  • 170
  • 301
Sunshine
  • 181
  • 1
  • 3
  • 15
  • That code which you provide does nothing but define a function. Please extract a [mcve] from your code and post that here. Also note that we don't have the file you're trying to read either! – Ulrich Eckhardt Jul 07 '19 at 11:40
  • What does `np.fromfile` do? Which dtypes have you tried? – hpaulj Jul 07 '19 at 12:43

0 Answers0