np.save() works with a reproducible example but not with my data.
How can I save my numpy array as binary?
np.save works in this reproducible example:
a = np.arange(12, dtype='float32').reshape(2,2,3)
a.shape
Out[42]: (2, 2, 3)
a.dtype
Out[43]: dtype('float32')
np.save("delme",a)
But not with my numpy array variable_data:
variable_data.shape
Out[45]: (3500, 480, 640)
variable_data.dtype
Out[46]: dtype('float32')
ma.is_masked(variable_data)
Out[52]: False
Then, I get an error:
np.save("delme2", variable_data)
---------------------------------------------------------------------------
NotImplementedError Traceback (most recent call last)
Cell In[41], line 3
1 variable_data.shape
2 variable_data.dtype
----> 3 np.save("delme2", variable_data)
File ~/miniforge3/envs/sediment/lib/python3.9/site-packages/numpy/lib/npyio.py:546, in save(file, arr, allow_pickle, fix_imports)
544 with file_ctx as fid:
545 arr = np.asanyarray(arr)
--> 546 format.write_array(fid, arr, allow_pickle=allow_pickle,
547 pickle_kwargs=dict(fix_imports=fix_imports))
File ~/miniforge3/envs/sediment/lib/python3.9/site-packages/numpy/lib/format.py:730, in write_array(fp, array, version, allow_pickle, pickle_kwargs)
728 else:
729 if isfileobj(fp):
--> 730 array.tofile(fp)
731 else:
732 for chunk in numpy.nditer(
733 array, flags=['external_loop', 'buffered', 'zerosize_ok'],
734 buffersize=buffersize, order='C'):
File ~/miniforge3/envs/sediment/lib/python3.9/site-packages/numpy/ma/core.py:6221, in MaskedArray.tofile(self, fid, sep, format)
6208 def tofile(self, fid, sep="", format="%s"):
6209 """
6210 Save a masked array to a file in binary format.
6211
(...)
6219
6220 """
-> 6221 raise NotImplementedError("MaskedArray.tofile() not implemented yet.")
NotImplementedError: MaskedArray.tofile() not implemented yet.