title: Load a npz in numpy from bytes
body: <p>I have a npz file saved from numpy that I can load by using <code>numpy.load(mynpzfile)</code>. However, I would like to save this file as a part of a binary file, packed with another file. Something like:</p>
  <pre><code>import numpy as np
  from PIL import Image
  from io import BytesIO
  
  # Saving file jointly
  input1 = open('animagefile.png', 'rb').read()
  input2 = open('npzfile.npz', 'rb').read()
  filesize = len(input1).to_bytes(4, 'big')
  
  output = filesize + input1 + input2
  
  with open('Output.bin', 'wb') as fp:
      fp.write(output)
  
  # Open them
  input1 = open('Output.bin', 'rb').read()
  filesize2 = int.from_bytes(input1[:4], &quot;big&quot;)
  
  segmentation = Image.open(BytesIO(input1[4:4+filesize2])) 
  # THIS LINE GIVES ME AN ERROR
  layouts = np.frombuffer(input2[4+filesize2:])
  </code></pre>
  <p>However, when reading back the npz I get an error. I have tried load and frombuffer, and both give me an error:</p>
  <ul>
  <li>frombuffer: <code>ValueError: buffer size must be a multiple of element size</code></li>
  <li>load: <code>ValueError: embedded null byte</code></li>
  </ul>
  <p>What can I do?</p>