python - 使用 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)
解决方案
您应该使用numpy.save和numpy.load。
推荐阅读
- php - 如何找出 Symfony 设置 PHPSESSID cookie 的原因/位置?
- apache-kafka - Apache Kafka 日志保留配置问题或如何配置 Kafka 保留策略?
- java - 如何使用 Apache POI 从特定行读取特定的 excel 列
- apache-spark - spark-cassnadra 连接器问题
- python - 返回 bin 坐标 python
- python - 在 Jupyter Notebook 中创建新笔记本时出错 [权限被拒绝]
- android - 多重扩展文件
- python - Python Cocos2d 调整大小后找不到资源图像
- python - 带有 Yattag 的 HTML 表格 - 创建新的 TR
- android - 无法在 WebView 中播放带有 html 的音频链接