将hdf5附加到另一个hdf5文件中

问题描述 投票:3回答:1

我有几个具有相同形状的hdf5文件,其中包含x和y列。我需要追加这些文件,以获得一个包含所有数据的hdf5文件。

到目前为止,我的代码:

def append_to_h5(new_file, file_list):
    f = h5py.File(new_file, 'a')
    for file in file_list:
        with h5py.File(file, 'r') as d:
            f.create_dataset("./", data=d)
    f.close()

#new_file <- is a file path to the new hdf5 file
#file_list <- contains all the pathes of the hdf5 files, which I want to append

错误

   in make_new_dset tid = h5t.py_create(dtype, logical=1)
  File "h5py/h5t.pyx", line 1634, in h5py.h5t.py_create
  File "h5py/h5t.pyx", line 1656, in h5py.h5t.py_create
  File "h5py/h5t.pyx", line 1717, in h5py.h5t.py_create
TypeError: No conversion path for dtype: dtype('<U1')

任何想法都值得赞赏谢谢

python append hdf5 h5py
1个回答
0
投票

这将涵盖更多其他SO答案。我创建了一个简短的示例来帮助您入门。主要更改是添加了一个循环来查找和复制顶级数据集(仅)。假定不会有数据集名称冲突,并且需要将测试用于一般用途。另外,我更改了您的文件对象变量名称。

def append_to_h5(new_file, file_list):
    f1 = h5py.File(new_file, 'a')
    for file in file_list:
        with h5py.File(file, 'r') as f2:
            for ds in f2.keys():
                f2.copy(ds, f1) 
    f1.close()

#new_file <- is a file path to the new hdf5 file
#file_list <- contains all the pathes of the hdf5 files, which I want to append
© www.soinside.com 2019 - 2024. All rights reserved.