diff options
author | Omar Merghany <omar.merghany95@gmail.com> | 2019-08-16 08:11:28 +0200 |
---|---|---|
committer | Matti Picus <matti.picus@gmail.com> | 2019-08-16 09:11:28 +0300 |
commit | 37e3f609259e8ac381ae9b2b4e5e8f340172b9f0 (patch) | |
tree | 637ddbedfc8c9378d360258509baa761df320117 /numpy/lib/npyio.py | |
parent | 0a133311b507151bb7506e9c6313b1d719c894ae (diff) | |
download | numpy-37e3f609259e8ac381ae9b2b4e5e8f340172b9f0.tar.gz |
DOC:Add example to clarify "numpy.save" behavior on already open file #10445 (#14070)
* DOC:Add example to clarify "numpy.save" behavior on already unclosed file
Diffstat (limited to 'numpy/lib/npyio.py')
-rw-r--r-- | numpy/lib/npyio.py | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/numpy/lib/npyio.py b/numpy/lib/npyio.py index 746e6043a..c45622edd 100644 --- a/numpy/lib/npyio.py +++ b/numpy/lib/npyio.py @@ -506,7 +506,9 @@ def save(file, arr, allow_pickle=True, fix_imports=True): Notes ----- For a description of the ``.npy`` format, see :py:mod:`numpy.lib.format`. - + + Any data saved to the file is appended to the end of the file. + Examples -------- >>> from tempfile import TemporaryFile @@ -519,6 +521,15 @@ def save(file, arr, allow_pickle=True, fix_imports=True): >>> np.load(outfile) array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) + + >>> with open('test.npy', 'wb') as f: + ... np.save(f, np.array([1, 2])) + ... np.save(f, np.array([1, 3])) + >>> with open('test.npy', 'rb') as f: + ... a = np.load(f) + ... b = np.load(f) + >>> print(a, b) + # [1 2] [1 3] """ own_fid = False if hasattr(file, 'write'): |