I have an array:
>>> data = np.ones((1,3,128))
I save it to file using savez_compressed:
>>> with open('afile','w') as f:
np.savez_compressed(f,data=data)
When I try to load it I don't seem to be able to access the data:
>>> with open('afile','r') as f:
b=np.load(f)
>>> b.files
['data']
>>> b['data']
Traceback (most recent call last):
File "", line 1, in
b['data']
File "C:\Python27\lib\site-packages\numpy\lib\npyio.py", line 238, in __getitem__
bytes = self.zip.read(key)
File "C:\Python27\lib\zipfile.py", line 828, in read
return self.open(name, "r", pwd).read()
File "C:\Python27\lib\zipfile.py", line 853, in open
zef_file.seek(zinfo.header_offset, 0)
ValueError: I/O operation on closed file
Am I doing something obviously wrong?
EDIT
Following @Saullo Castro's answer I tried this:
>>> np.savez_compressed('afile.npz',data=data)
>>> b=np.load('afile.npz')
>>> b.files
['data']
>>> b['data']
and got the following error:
<