title: Ensuring python equivalence of matlab's `fread`
body: <p>I have a binary test file found at <a href="http://jmp.sh/VpTZxgQ" rel="nofollow">http://jmp.sh/VpTZxgQ</a> and I am trying to rewrite some matlab code in python which reads this file.</p>
  
  <p>What I have realised is that matlab's <code>fread</code> remembers what has already been read so that it skips the number of bytes that have already been read. How do I ensure I get the same behaviour in python?</p>
  
  <h1>Matlab Code:</h1>
  
  <pre><code>clear all; close all;
  
  path = pwd;
  ext = 'bin';
  stem = 'test';
  filename = [stem,'.',ext];
  filename = fullfile(path,filename);
  fid = fopen(filename,'r');
  
  fread(fid,2,'int16')
  fread(fid,32,'char')
  fread(fid,2,'int16')
  </code></pre>
  
  <h1>Python Code:</h1>
  
  <pre><code>import numpy as np  
  
  def fread(filename, n, precision):
       with open(filename, 'rb') as fid:
           data_array = np.fromfile(fid, precision).reshape((-1, 1)).T
  
       return data_array[0,0:n]
  
  print fread('test.bin', 2, np.int16)                                                                                                                         
  print fread('test.bin', 32, np.str)
  print fread('test.bin', 2, np.int16) 
  </code></pre>
  
  <p>Ideally I would want the output of these formulations to be the same, but they are not. In fact python gives a <code>value error</code> when I try to set <code>precision</code> to <code>np.str</code>...</p>
  
  <p>As a bonus question - I'm assuming that reading a binary file and making sense of the data requires that the user has an understanding of how the data was formatted in order to make any sensible information of the data. Is this true?</p>