如何在关闭文件后将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组,所以我想在处理加载到内存中的数据之前关闭这些文件。这是不可能的吗?
发布于 2014-11-25 00:55:04
使用.value从数据集中提取所需的变量。
示例:
import h5py
feature_file = h5py.File(worm_file_path, 'r')
worm_features = feature_file["worm"].value
feature_file.close()
print worm_features发布于 2020-12-20 00:56:28
关闭hdf5文件后,使用[:]将dataset的值复制到变量,以便能够访问dataset。
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'https://stackoverflow.com/questions/26517795
复制相似问题