【问题标题】:Appending more datasets into an existing Hdf5 file without deleting other groups and datasets将更多数据集附加到现有 Hdf5 文件中,而不删除其他组和数据集
【发布时间】:2016-11-06 07:26:09
【问题描述】:

我有一个 HDF5 文件,其中包含包含数据集的组和子组。我想打开文件并将一些数据集添加到组中。我采用了以下在python中非常简单的方法。

    import h5py
    f = h5py.File('filename.h5','w')
    f.create_dataset('/Group1/subgroup1/dataset4', data=pngfile)
    f.close()

之前的文件是这样的

文件看起来像这样

但我希望它不删除其他数据集和组,而只是将 dataset4 追加到行中。

【问题讨论】:

    标签: python dataset hdf5 h5py


    【解决方案1】:

    就像 Python 的 open() 函数一样,'w' 将截断任何现有文件。使用 'a' 模式向文件添加内容:

    import h5py
    f = h5py.File('filename.h5','a')
    f.create_dataset('/Group1/subgroup1/dataset4', data=pngfile)
    f.close()
    

    【讨论】:

      猜你喜欢
      • 2014-07-19
      • 2021-02-17
      • 2014-12-19
      • 2015-03-06
      • 2013-03-01
      • 2010-10-01
      • 2022-11-12
      • 2013-02-26
      • 2017-11-03
      相关资源
      最近更新 更多