title: Reading a binary .dat file as an array
body: <p>I have a code that goes through several iterations. In each iteration, the code generates a numpy based array. I append the numpy based array to an existing binary .dat file. I use the following code to generate the data:</p>
  
  <pre><code>WholeData = numpy.concatenate((Location,Data),axis=0)  
  # Location &amp; Data are two numpy arrays
  DataBinary = open('DataBinary.dat','ab')
  WholeData.tofile(DataBinary)
  DataBinary.close()
  </code></pre>
  
  <p>I am trying to read the whole binary file into an array. I am having the following difficulties:</p>
  
  <ol>
  <li><p>I tried the following code:</p>
  
  <pre><code>NewData = numpy.array('f')
  File1 = open('DataBinary.dat','rb')
  NewData.fromstring(File1.read())
  File1.close()
  </code></pre>
  
  <p>Error status:</p>
  
  <blockquote>
    <p>Traceback (most recent call last):
     File "", line 1, in 
    AttributeError: 'numpy.ndarray' object has no attribute 'fromstring'</p>
  </blockquote></li>
  <li><p>I tried to use an array based array and then read the file into the array.</p>
  
  <pre><code>from array import array
  File1 = open('DataBinary.dat','rb')
  NewData.fromstring(File1.read())
  File1.close()
  </code></pre></li>
  </ol>
  
  <p>However, <code>NewData</code> is erroneous, i.e., it is not same as <code>WholeData</code>. I guess that saving the data as <code>numpy.array</code> and reading it as <code>array.array</code> might not be a good option.</p>
  
  <p>Any suggestion will be appreciated.</p>