python - 以 mmap 模式从 .npy 文件加载字典
问题描述
因此,我有许多大型 .npy 文件(每个约 600MB),其结构如下:
file = {"date": current_date, "some parameters": parameters, "data": data}
numpy.save("file.npy", file)
数据字段包含一个大数组(每个元素中都有字典!),它对文件大小的贡献最大,因此我想以 mmap 模式加载文件,否则文件打开过程(np.load()。即使我只想访问“日期”字段,item()) 也太长了。
但是,在 mmap_mode='r' 中加载文件不起作用,因为文件中有字典。
np.load("test.npy", mmap_mode='r')
引发 ValueError 异常:
ValueError: Array can't be memory-mapped: Python objects in dtype.
我还能做些什么来加快文件打开时间?我现在无法重写它们,所以不建议使用 PyTables 和其他数据库等替代解决方案。我确实意识到这里数据存储问题的解决方案是愚蠢的。
解决方案
推荐阅读
- javascript - 在 Chrome 71+ 上激活触摸事件
- c# - 如何将数据绑定到 Windows 窗体应用程序中的 DataGridView?
- android - ViewModel 类实现 LifecycleObserver 可以吗?
- javascript - 保存时更新 UI:本地与服务器
- android - 如何解决“Android/Sdk/ndk-bundle/ndk-build.cmd”以非零退出值 2 / 退出值 -1 结束
- typescript - 如何从 `tsconfig.json` 获取 `CompilerOptions`
- python - 安然分类 - 以错误的方式阅读电子邮件
- android-studio - 如何使用 SDK tools-version 26.1.1 安装 android SDK
- php - 图像旋转不适用于托管环境,但适用于 localhost
- python - Matplotlibrc 需要更新吗?