使用 Pickle 保存 Numpy 数组
问题描述:
我有一个我想保存的 Numpy 数组 (130,000 x 3),我想使用 Pickle 保存,使用以下代码.但是,我一直在 pkl.load 行收到错误EOFError:输入不足"或UnsupportedOperation:读取".这是我第一次使用 Pickle,有什么想法吗?
I've got a Numpy array that I would like to save (130,000 x 3) that I would like to save using Pickle, with the following code. However, I keep getting the error "EOFError: Ran out of input" or "UnsupportedOperation: read" at the pkl.load line. This is my first time using Pickle, any ideas?
谢谢,
阿南特
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)