Repository: numpy/numpy

Issue:
Warning expected for re-writing array to already open file
Hello,

I am using Numpy v1.14 on Mac OSX with Python 2.7.

Consider the following snippet:
```python
>>> f = open('test.npy', 'w')
>>> a = [1,2]
>>> np.save(f, np.asarray(a))
>>> aa = [1, 3]
>>> np.save(f, np.asarray(aa))  # No effect of this
>>> f.close()
>>> ff = open('test.npy', 'r')
>>> bb = np.load('test.npy')
>>> bb
np.array([1, 2]) # Expectation was np.array([1,3])
```
I think there should be at least a warning on overwriting the already written and unclosed file. In the worst case, I think there should be a mention in the documentation.

I believe this is an extreme boundary case. In general, this may not be the way one should use `np.save`. But when I designed my structure of the code and the classes, I simply assumed that this should work and after 3 hours of simulations, only the first iteration value was saved.

Kindly look at it. Let me know if you need further information.

Thank you.


Discussion:
Actually, fun fact, but all of the results *are* saved. Because save just adds more stuff, if you load again, you will in fact get the next array IIRC.
Anyway, I am a bit unsure if I think a warning is good. If you pass in a file object, I think you might actually want to do something like this where you write more then just this array into the new file object. OTOH, yes that use case may be pretty rare.

EDIT: Just to note again, it is not like numpy overwrites your data (unless you manually jump around in the file)
Yep, works as designed:

```python
with open('test.npy', 'wb') as f:   # b needed for python 3
	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]
```

So you should be able to extract all of your simulation results from your file
I understand. Thank you.

Should there be a sentence in the documentation explaining this queueing of stored variables? Someone doing rare things can plan beforehand.

If you guys think it's fine without it, then feel free to close the issue. Thank you for the clarification.
Changing the wording to "write" instead of "save" might be an improvement, since save does imply a single value is store, whereas write implies `file.write` which appends to the end.
Well, but we do not open "w+" if it is a string ("obviously"), so I guess half a sentence that a file object its written might make sense. Or just something into the direction of "Filename to which data is saved or file to which data is written"….

Resolving patch:
diff --git a/numpy/lib/npyio.py b/numpy/lib/npyio.py
--- 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, 'read'):


Test patch: