gpt4 book ai didi

python - 关闭文件后如何在内存中保留一个 h5py 组?

转载 作者:太空宇宙 更新时间:2023-11-04 01:12:59 24 4
gpt4 key购买 nike

关闭文件后如何在内存中保留一个 h5py 组?

在以下代码之后:

import h5py

feature_file = h5py.File(worm_file_path, 'r')
worm_features = feature_file["worm"]

我可以访问 worm_features因为它是 h5py group ( <HDF5 group "/worm" (4 members)> )

但是在我运行该行之后:

feature_file.close()

我无法再访问 worm_features .它现在显示为 <Closed HDF5 group> .

因为我需要为大约 20 个文件加载 worm_features h5py 组,所以我想在处理我加载到内存中的数据之前关闭这些文件。这不可能吗?

最佳答案

使用 .value 从数据集中提取所需的变量。

例子:

import h5py

feature_file = h5py.File(worm_file_path, 'r')
worm_features = feature_file["worm"].value
feature_file.close()
print worm_features

关于python - 关闭文件后如何在内存中保留一个 h5py 组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26517795/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com