我有一个 HDF5 文件,其中包含组和子组,其中有数据集。我想打开文件并将一些数据集添加到组中。我采用了以下在 python 中非常简单的方法。
import h5py
f = h5py.File('filename.h5','w')
f.create_dataset('/Group1/subgroup1/dataset4', data=pngfile)
f.close()
之前的文件是这样的
修改后的文件是这样的
但我希望它不删除其他数据集和组,而只是将 dataset4 添加到行中。
最佳答案
就像 Python open() 函数一样,'w' 将截断任何现有文件。使用 'a' 模式向文件添加内容:
import h5py
f = h5py.File('filename.h5','a')
f.create_dataset('/Group1/subgroup1/dataset4', data=pngfile)
f.close()
关于python - 在不删除其他组和数据集的情况下将更多数据集附加到现有 Hdf5 文件中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38186816/