使用 Pickle 保存 Numpy 数组 [英] Save Numpy Array using Pickle

查看:402
本文介绍了使用 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)

推荐答案

你应该使用 numpy.savenumpy.load.

这篇关于使用 Pickle 保存 Numpy 数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆