Using Spyder / Python to Open .npy File
.npy
files are binary files.Do not try to open it with Spyder or any text editor; what you see may not make sense to you.
Instead, load the .npy
file using the numpy
module (reference: http://docs.scipy.org/doc/numpy-1.10.1/reference/generated/numpy.load.html).
Code sample:
First, import numpy. If you do not have it, install (here's how: http://docs.scipy.org/doc/numpy/user/install.html)
>>> import numpy as np
Let's set a random numpy array as variable array
.
>>> array = np.random.randint(1,5,10)>>> print array[2 3 1 2 2 3 1 2 3 3]
To export to .npy
file, use np.save(FILENAME, OBJECT)
where OBJECT = array
>>> np.save('test.npy', array)
You can load the .npy
file using np.load(FILENAME)
>>> array_loaded = np.load('test.npy')
Let's compare the original array
vs the one loaded from file (array_loaded
)
>>> print 'Loaded: ', array_loadedLoaded: [2 3 1 2 2 3 1 2 3 3]>>> print 'Original:', arrayOriginal: [2 3 1 2 2 3 1 2 3 3]