title: How do I read from binary file to an array of int16 in python
body: <p>I'm trying to parse a a binary file. the file contains a few data packets each one starts with a timestamp then definition of an array (rows and columns each an int32)the the array itself. I've started with trying to parse a single packet but I have a problem with reading the array:</p>
  
  <pre><code>tsSize = 8
  rowSize = 4
  columnSize=4
  thresholdVectorSize=4
  targetsCandidatesVectorSize=4
  centerOfMassVectorSize=4
  bytesReadUpToNow=0
  with open("C:\\outputs\\out.bin", mode='rb') as file: # b is important -&gt; binary
      fileContent = file.read()   
      TimeS = struct.unpack("Q", fileContent[bytesReadUpToNow:bytesReadUpToNow+tsSize])[0]
      bytesReadUpToNow+=tsSize
      dt =datetime.datetime.fromtimestamp(TimeS/1000.0)
      rows, columns = struct.unpack("ii", fileContent[bytesReadUpToNow:bytesReadUpToNow+rowSize+columnSize])
      bytesReadUpToNow=bytesReadUpToNow+rowSize+columnSize
      data = struct.unpack("h" * (rows*columns), fileContent[bytesReadUpToNow:rows*columns*2+bytesReadUpToNow])[0]
      print(sys.getsizeof(data))
      print(type(data))
  </code></pre>
  
  <p>Is there a way to predefined size of an array in python?</p>