title: How can I read successive arrays from a binary file using `np.fromfile`?
body: <p>I want to read a binary file in Python, the exact layout of which is stored in the binary file itself.</p>
  
  <p>The file contains a sequence of two-dimensional arrays, with the row and column dimensions of each array stored as a pair of integers preceding its contents. I want to successively read all of the arrays contained within the file.</p>
  
  <p>I know this can be done with <code>f = open("myfile", "rb")</code> and <code>f.read(numberofbytes)</code>, but this is quite clumsy because I would then need to convert the output into meaningful data structures. I would like to use numpy's <code>np.fromfile</code> with a custom <code>dtype</code>, but have not found a way to read part of the file, leaving it open, and then continue reading with a modified <code>dtype</code>.</p>
  
  <p>I know I can use <code>os</code> to <code>f.seek(numberofbytes, os.SEEK_SET)</code> and <code>np.fromfile</code> multiple times, but this would mean a lot of unnecessary jumping around in the file. </p>
  
  <p>In short, I want MATLAB's <code>fread</code> (or at least something like C++ <code>ifstream</code> <code>read</code>).</p>
  
  <p>What is the best way to do this?</p>