问题
I'm using np.save/np.load to save my data into files and read from another script. Although the code is working properly under both windows and linux, there's a problem when i try to load my .npy files created in linux, with my windows setup. In both cases, i'm using python 3.6, with packages up to date (numpy version is same).
I noticed that this happens only in arrays with dtype=object, and not other type of arrays. The error I get is "TypeError: _reconstruct: First argument must be a sub-type of ndarray".
I tried to change allow_pickle parameter in np.save to False, but it didn't work (it wouldn't allow me to save several arrays).
Any idea what's wrong? Any suggestions on a different way to keep my data cross-platform?
Thanks
Edit: I tried some simple experiments with dictionaries and numpy arrays, and it turns out the problem exists in different configurations.
For example, pickle.dump() works for dictionaries if I export in Unix and load (pickle.load) on Windows, but not with numpy arrays.
On the other hand, np.save()/np.load() works for non-object numpy arrays, but not for dictionaries, when I export in Unix and load on Windows.
Both these methods fail for numpy objects or lists of arrays (e.g. list of np.arrays with different shapes)
Of course, np.save/np.load works properly for all kinds of data, given that the I use the same platform.
Any further ideas? I tried the hdf5 format, but I still get some errors.
来源:https://stackoverflow.com/questions/54369919/numpy-load-error-when-using-different-platforms