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

Function _savez

numpy/lib/npyio.py:713–747  ·  view source on GitHub ↗
(file, args, kwds, compress, allow_pickle=True, pickle_kwargs=None)

Source from the content-addressed store, hash-verified

711
712
713def _savez(file, args, kwds, compress, allow_pickle=True, pickle_kwargs=None):
714 # Import is postponed to here since zipfile depends on gzip, an optional
715 # component of the so-called standard library.
716 import zipfile
717
718 if not hasattr(file, 'write'):
719 file = os_fspath(file)
720 if not file.endswith('.npz'):
721 file = file + '.npz'
722
723 namedict = kwds
724 for i, val in enumerate(args):
725 key = 'arr_%d' % i
726 if key in namedict.keys():
727 raise ValueError(
728 "Cannot use un-named variables and keyword %s" % key)
729 namedict[key] = val
730
731 if compress:
732 compression = zipfile.ZIP_DEFLATED
733 else:
734 compression = zipfile.ZIP_STORED
735
736 zipf = zipfile_factory(file, mode="w", compression=compression)
737
738 for key, val in namedict.items():
739 fname = key + '.npy'
740 val = np.asanyarray(val)
741 # always force zip64, gh-10776
742 with zipf.open(fname, 'w', force_zip64=True) as fid:
743 format.write_array(fid, val,
744 allow_pickle=allow_pickle,
745 pickle_kwargs=pickle_kwargs)
746
747 zipf.close()
748
749
750def _ensure_ndmin_ndarray_check_param(ndmin):

Callers 2

savezFunction · 0.85
savez_compressedFunction · 0.85

Calls 5

zipfile_factoryFunction · 0.85
endswithMethod · 0.80
keysMethod · 0.80
openMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected