gpt4 book ai didi

python - 使用 Pickle 保存 Numpy 数组

转载 作者:太空狗 更新时间:2023-10-29 22:03:58 24 4
gpt4 key购买 nike

我有一个 Numpy 数组,我想使用 Pickle 保存它 (130,000 x 3),代码如下。但是,我不断在 pkl.load 行收到错误“EOFError:输入不足”或“UnsupportedOperation:read”。这是我第一次使用 Pickle,有什么想法吗?

谢谢,

阿南特

import pickle as pkl
import numpy as np

arrayInput = np.zeros((1000,2)) #Trial input
save = True
load = True

filename = path + 'CNN_Input'
fileObject = open(fileName, 'wb')

if save:
pkl.dump(arrayInput, fileObject)
fileObject.close()

if load:
fileObject2 = open(fileName, 'wb')
modelInput = pkl.load(fileObject2)
fileObject2.close()

if arrayInput == modelInput:
Print(True)

最佳答案

你应该使用 numpy.savenumpy.load .

关于python - 使用 Pickle 保存 Numpy 数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52444921/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com