summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2017-01-17 11:43:39 -0700
committerGitHub <noreply@github.com>2017-01-17 11:43:39 -0700
commit8940a6533132ab11edbd0520ee0f0329c3a7f329 (patch)
tree877c33a8aa43f7624f27c347537832ce99a166fb /numpy
parent6f378b36f16d1667704234a2f6287588a04e210b (diff)
parentfca6cd8d66b7662fe571db8a9eb0ccb75c4cbee4 (diff)
downloadnumpy-8940a6533132ab11edbd0520ee0f0329c3a7f329.tar.gz
Merge pull request #8470 from MartinThoma/savez_compressed_docs
DOC: Add example to np.savez_compressed
Diffstat (limited to 'numpy')
-rw-r--r--numpy/lib/npyio.py50
1 files changed, 44 insertions, 6 deletions
diff --git a/numpy/lib/npyio.py b/numpy/lib/npyio.py
index 13eb5cefc..c575cc030 100644
--- a/numpy/lib/npyio.py
+++ b/numpy/lib/npyio.py
@@ -603,18 +603,56 @@ def savez_compressed(file, *args, **kwds):
Parameters
----------
- file : str
- File name of ``.npz`` file.
- args : Arguments
- Function arguments.
- kwds : Keyword arguments
- Keywords.
+ file : str or file
+ Either the file name (string) or an open file (file-like object)
+ where the data will be saved. If file is a string or a Path, the
+ ``.npz`` extension will be appended to the file name if it is not
+ already there.
+ args : Arguments, optional
+ Arrays to save to the file. Since it is not possible for Python to
+ know the names of the arrays outside `savez`, the arrays will be saved
+ with names "arr_0", "arr_1", and so on. These arguments can be any
+ expression.
+ kwds : Keyword arguments, optional
+ Arrays to save to the file. Arrays will be saved in the file with the
+ keyword names.
+
+ Returns
+ -------
+ None
See Also
--------
+ numpy.save : Save a single array to a binary file in NumPy format.
+ numpy.savetxt : Save an array to a file as plain text.
numpy.savez : Save several arrays into an uncompressed ``.npz`` file format
numpy.load : Load the files created by savez_compressed.
+ Notes
+ -----
+ The ``.npz`` file format is a zipped archive of files named after the
+ variables they contain. The archive is compressed with
+ ``zipfile.ZIP_DEFLATED`` and each file in the archive contains one variable
+ in ``.npy`` format. For a description of the ``.npy`` format, see
+ `numpy.lib.format` or the NumPy Enhancement Proposal
+ http://docs.scipy.org/doc/numpy/neps/npy-format.html
+
+ When opening the saved ``.npz`` file with `load` a `NpzFile` object is
+ returned. This is a dictionary-like object which can be queried for
+ its list of arrays (with the ``.files`` attribute), and for the arrays
+ themselves.
+
+ Examples
+ --------
+ >>> test_array = np.random.rand(3, 2)
+ >>> test_vector = np.random.rand(4)
+ >>> np.savez_compressed('/tmp/123', a=test_array, b=test_vector)
+ >>> loaded = np.load('/tmp/123.npz')
+ >>> print(np.array_equal(test_array, loaded['a']))
+ True
+ >>> print(np.array_equal(test_vector, loaded['b']))
+ True
+
"""
_savez(file, args, kwds, True)