首页 > 解决方案 > 使用 Pickle 保存 Numpy 数组

问题描述

我有一个我想使用 Pickle 保存的 Numpy 数组(130,000 x 3),代码如下。但是,我在 pkl.load 行中不断收到错误“EOFError: Ran out of input”或“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)

标签: pythonnumpypickle

解决方案


您应该使用numpy.savenumpy.load


推荐阅读