MCPcopy Create free account
hub / github.com/numpy/numpy / savez_compressed

Function savez_compressed

numpy/lib/npyio.py:648–710  ·  view source on GitHub ↗

Save several arrays into a single file in compressed ``.npz`` format. Provide arrays as keyword arguments to store them under the corresponding name in the output file: ``savez(fn, x=x, y=y)``. If arrays are specified as positional arguments, i.e., ``savez(fn, x, y)``, their n

(file, *args, **kwds)

Source from the content-addressed store, hash-verified

646
647@array_function_dispatch(_savez_compressed_dispatcher)
648def savez_compressed(file, *args, **kwds):
649 """
650 Save several arrays into a single file in compressed ``.npz`` format.
651
652 Provide arrays as keyword arguments to store them under the
653 corresponding name in the output file: ``savez(fn, x=x, y=y)``.
654
655 If arrays are specified as positional arguments, i.e., ``savez(fn,
656 x, y)``, their names will be `arr_0`, `arr_1`, etc.
657
658 Parameters
659 ----------
660 file : str or file
661 Either the filename (string) or an open file (file-like object)
662 where the data will be saved. If file is a string or a Path, the
663 ``.npz`` extension will be appended to the filename if it is not
664 already there.
665 args : Arguments, optional
666 Arrays to save to the file. Please use keyword arguments (see
667 `kwds` below) to assign names to arrays. Arrays specified as
668 args will be named "arr_0", "arr_1", and so on.
669 kwds : Keyword arguments, optional
670 Arrays to save to the file. Each array will be saved to the
671 output file with its corresponding keyword name.
672
673 Returns
674 -------
675 None
676
677 See Also
678 --------
679 numpy.save : Save a single array to a binary file in NumPy format.
680 numpy.savetxt : Save an array to a file as plain text.
681 numpy.savez : Save several arrays into an uncompressed ``.npz`` file format
682 numpy.load : Load the files created by savez_compressed.
683
684 Notes
685 -----
686 The ``.npz`` file format is a zipped archive of files named after the
687 variables they contain. The archive is compressed with
688 ``zipfile.ZIP_DEFLATED`` and each file in the archive contains one variable
689 in ``.npy`` format. For a description of the ``.npy`` format, see
690 :py:mod:`numpy.lib.format`.
691
692
693 When opening the saved ``.npz`` file with `load` a `NpzFile` object is
694 returned. This is a dictionary-like object which can be queried for
695 its list of arrays (with the ``.files`` attribute), and for the arrays
696 themselves.
697
698 Examples
699 --------
700 >>> test_array = np.random.rand(3, 2)
701 >>> test_vector = np.random.rand(4)
702 >>> np.savez_compressed('/tmp/123', a=test_array, b=test_vector)
703 >>> loaded = np.load('/tmp/123.npz')
704 >>> print(np.array_equal(test_array, loaded['a']))
705 True

Callers

nothing calls this directly

Calls 1

_savezFunction · 0.85

Tested by

no test coverage detected