title: Python read binary file of unsigned 16 bit integers
body: <p>I must read a binary file in Python, and store its content in an array. The information I have on this file is that</p>
  
  <pre><code>filename.bin is of size 560x576 (height x width) with 16 b/p, i.e., unsigned 16-bit integer for each pixel
  </code></pre>
  
  <p>This is what I have been able to come up with so far:</p>
  
  <pre><code>import struct
  import numpy as np
  fileName = "filename.bin"
  
  with open(fileName, mode='rb') as file: 
      fileContent = file.read()
  
  
  
  a = struct.unpack("I" * ((len(fileContent)) // 4), fileContent)
  
  a = np.reshape(a, (560,576))
  </code></pre>
  
  <p>However I get the error</p>
  
  <pre><code>cannot reshape array of size 161280 into shape (560,576)
  </code></pre>
  
  <p>161280 is exactly half of <code>560 x 576 = 322560</code>. I would like to understand what I am doing wrong and how to read the binary file and reshape in the required form.</p>