Skip to content

Commit

Permalink
DOC:Add example to clarify "numpy.save" behavior on already open file n…
Browse files Browse the repository at this point in the history
…umpy#10445 (numpy#14070)

* DOC:Add example to clarify "numpy.save" behavior on already unclosed file
  • Loading branch information
OmarMerghany authored and mattip committed Aug 16, 2019
1 parent 0a13331 commit 37e3f60
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion numpy/lib/npyio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'):
Expand Down

0 comments on commit 37e3f60

Please sign in to comment.