简体   繁体   English

使用 numpy.save 保存并使用 pickle.load 加载时出错

[英]Error when saving with numpy.save and loading with pickle.load

I've saved a simple numpy array by doing:我通过执行以下操作保存了一个简单的 numpy 数组:

numpy.save(filepath, anarray)

I'm now trying to retrieve it using pickle (I don't want to switch to numpy.load because the code has to be flexible), but I get:我现在正在尝试使用 pickle 检索它(我不想切换到 numpy.load 因为代码必须灵活),但我得到:

atuple = pickle.load(open(filepath, 'rb'))

_pickle.UnpicklingError: STACK_GLOBAL requires str

Numpy and pickle use different file formats. Numpy 和 pickle 使用不同的文件格式。 There's no reason to expect that you should be able to unpickle an array saved using np.save .没有理由期望您应该能够取消使用np.save保存的数组。 If you need to be able to load things with pickle, you should save them with pickle.如果你需要能够用泡菜加载东西,你应该用泡菜保存它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM