Numpy.load() error when using different platforms

爱⌒轻易说出口 提交于 2019-12-24 11:29:58

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!