Created
June 9, 2017 02:56
-
-
Save qiuwch/00f4fc5fdf2a047b1a206850a8aa306c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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