![](/img/trans.png)
[英]How do I add values in parallel to an existing HDF5 file with 3 groups and 12 datasets in each group using h5py?
[英]How do I keep an h5py group in memory after closing the file?
关闭文件后如何将 h5py 组保留在内存中?
在以下代码之后:
import h5py
feature_file = h5py.File(worm_file_path, 'r')
worm_features = feature_file["worm"]
我可以访问worm_features
因为它是一个h5py 组( <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
使用[:]
将数据集的值复制到变量中,以便在关闭 hdf5 文件后访问数据集。
import h5py
feature_file = h5py.File(worm_file_path, 'r')
worm_features = feature_file["worm"] [:]
feature_file.close()
print (worm_features)
.value
对我不起作用并引发以下错误:
AttributeError: 'Dataset' object has no attribute 'value'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.