Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 6th, 2012  |  syntax: None  |  size: 0.44 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Can I add extra header information to a numpy .npy file by using seek?
  2. from tempfile import TemporaryFile
  3. outfile = TemporaryFile()
  4. # Write header to first 'n' bytes.
  5. ...
  6. # Write the array after the header.
  7. outfile.seek(n)
  8. x = np.arange(10)
  9. np.save(outfile, x)
  10.  
  11. # Then to read it back in:
  12. outfile.seek(0)
  13. # Read the header.
  14. ...
  15. # Read the array.
  16. outfile.seek(n)
  17. y = np.load(outfile)
  18.        
  19. foobar.npy
  20. foobar.meta
  21.        
  22. foobar.npy
  23. foobar.npy.meta