NumPy's load()
function returns a lazy file loader, not the actual data, when loading a npz
file. How to load a npz
file so that the data get loaded in memory?
相关问题
- Unable to load a previously dumped pickle file in
- Memory for python.exe on Windows 7 python 32 - Num
- Flush single app django 1.9
- How to perform element-wise custom function with t
- Repeat but in variable sized chunks in numpy
相关文章
- Numpy matrix of coordinates
- Python has stopped working
- implementing R scale function in pandas in Python?
- Is there a size limit for HTTP response headers on
- Numpy array to TFrecord
- Does there exist empty class in python?
- Is there a standard way to store XY data in python
- ImportError: No module named twisted.persisted.sty
I think you answered your question in the previous one about speed:
The file contents are now in memory.
The
.npz
file is a zip archive, with multiple arrays. The reason for makingload
a 2 step operation is that you might always want to load all arrays at once. It lets you loadx
without loadingy
.You could use a system zip archive tool to extract one or more of the files, and then load that directly. That can be a useful step just to better understand the file structure.
To be any more direct you need to study
np.lib.npyio.NpzFile
and maybe thegzip
module.If you want to force the contents of the arrays to be read and decompressed, just assign their contents to variables, e.g.:
If you wanted to keep the exact same syntax as with the lazy loader, you could simply load all of the arrays into a dict, e.g.:
So now you could use
to refer to
a
in later parts of your script. Personally I wouldn't keep the dict around, though, since the fact that it holds references to all of the arrays would prevent any individual unused ones from being garbage collected later on in your script.