I tried this simple code:
import numpy as np
np.save('tmp.npy', np.empty(128))
tmp = np.load('tmp.npy', mmap_mode='r+')
np.save('tmp.npy', tmp[:64])
It returned OSError:
---------------------------------------------------------------------------
OSError Traceback (most recent call last)
Cell In[1], line 4
2 np.save('tmp.npy', np.empty(128))
3 tmp = np.load('tmp.npy', mmap_mode='r+')
----> 4 np.save('tmp.npy', tmp[:64])
File <__array_function__ internals>:180, in save(*args, **kwargs)
File c:\Users\User\Documents\KULIAH\LAB_SOFTWARE\python_proj\anagrambotid\.venv\lib\site-packages\numpy\lib\npyio.py:518, in save(file, arr, allow_pickle, fix_imports)
516 if not file.endswith('.npy'):
517 file = file + '.npy'
--> 518 file_ctx = open(file, "wb")
520 with file_ctx as fid:
521 arr = np.asanyarray(arr)
OSError: [Errno 22] Invalid argument: 'tmp.npy'
My OS is Windows 11, I think on linux it would be worked fine. What happened here?
Even using tmp.flush() changes nothing.