title: Converting Python buffer to NumPy array - ValueError: buffer size must be a multiple of element size
body: <p>I'm attempting to read a BLOB object from a MySQL database in Python. The BLOB object is a NumPy array. </p>
  
  <p>To convert the array to a buffer type for insertion into the database I use the following function:</p>
  
  <p><code>numpy.getbuffer(arr)</code></p>
  
  <p>Upon reading back I am able to recreate the buffer object via:</p>
  
  <p><code>bytes(memoryview(arr))</code></p>
  
  <p><em>Everything is working correctly at this point.</em> My issue arises when using the below function on the buffer object in an attempt to convert it back to a NumPy array: </p>
  
  <p><code>numpy.frombuffer(arr, dtype=numpy.float64)</code></p>
  
  <p>The error is as follows:</p>
  
  <p><code>ValueError: buffer size must be a multiple of element size</code></p>
  
  <p>Please note that the dtype is set correctly, my Python version is 2.7.13 and NumPy is 1.13.3.</p>
  
  <p>EDIT: So upon doing some further digging, here is some extra information and a peculiarity on which I have stumbled: </p>
  
  <p>The length of the <code>numpy.getbuffer(arr)</code> object is 7392. If I print the length of the returned value as is from the MySQL DB (returned using <code>cursor.fetchall() or fetchone()</code> for example, the length is 7668.</p>
  
  <p>So I printed the first 30 characters of each object, and while they are clearly the same thing, the object returned from the DB has a number of additional characters: </p>
  
  <p>Before DB:
  <code>?=G????B?i?j??w??LG???ࢩ?a</code></p>
  
  <p>After DB:
  <code>'?=G????B?i?\0j??w??LG???ࢩ?</code></p>
  
  <p>I assume that the issue stems from the way the data is stored in the DB. My reasoning is that the following code produces no errors: </p>
  
  <p><code>numpy.frombuffer(numpy.getbuffer(arr), dtype=numpy.float64)</code> </p>
  
  <p>Thanks,
  Adam</p>