Skip to content

Instantly share code, notes, and snippets.

@qiuwch
Created June 9, 2017 02:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save qiuwch/00f4fc5fdf2a047b1a206850a8aa306c to your computer and use it in GitHub Desktop.
Save qiuwch/00f4fc5fdf2a047b1a206850a8aa306c to your computer and use it in GitHub Desktop.
import numpy as np
import StringIO
filename = 'C:/qiuwch/workspace/cnpy/cnpy/cnpy/arr1.npy'
arr = np.load(filename)
print 'Loading from file %s is done' % filename
print arr.shape
# (64, 64, 128) = 524288
# 8388688, file size
# What is the correct way to load numpy array from a memory string?
f = open(filename, 'rb') # Make sure use the binary mode, otherwise the read will stop early
txt = f.read()
print 'Loaded file size is %s' % len(txt)
np.load(StringIO.StringIO(txt)) # This can work!
# Expect size 262144, got 1149
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment