Load compressed data (.npz) from file using numpy.load

I do have the same problem(AssertionError) when using numpy 1.7.1/1.8.0 with python 2.7.6 both on MAC OS and Windows. But the problem was automatically fixed after I switch to linux with python 2.7.5. Then I reinstall python 2.7.5 on MACOS and Windows and all the problem was gone. Basically the problem is with python instead of numpy as the compiler is sending alert.So mightly the version matters.

But though npy is the serializable type of numpy, I don't think the file is small enough even with savez_compressed for large matrix.

Hopefully your problem is the same with mine


Try opening the file as binary:

with open('afile','rb') as f:

When using numpy.load you can pass the file name, and if the extension is .npz, it will first decompress the file:

np.savez_compressed('filename.npz', array1=array1, array2=array2)
b = np.load('filename.npz')

and do b['array1'] and so forth to retrieve the data from each array...


You can also use the f attribute, which leaves you with a np.ndarray:

images = np.load('images.npz')
images = images.f.arr_0

The name/key of the array inside the .npz-file (e.g. arr_0) can be found through

images.keys()

Note: The f attribute is not documented in the docstring of load. When load reads an npz file, it returns an instance of the class NpzFile. This class is available as numpy.lib.npyio.NpzFile. The docstring of the NpzFile class describes the f attribute. (As of this writing, the source code of the class can be found here.