关闭文件后如何在内存中保留一个 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
我是一名优秀的程序员,十分优秀!