如何使用python组合多个.h5文件(但形状相同)?

如何使用python组合多个.h5文件(但形状相同)?

我有 10,000 个 .h5 文件用于 3D 点云。

它们具有相同的形状。

我想合并(或合并)2000 个文件,所以我总共可以有 5 个大的 .h5 文件。(比如python中的append()函数)

我从 h5py( http://docs.h5py.org/en/latest/high/group.html ) 中找到了 copy() 函数。

但是,我无法将这种方法应用于我的问题。

请参考我的示例代码或帮助我解决我的问题。


慕妹3146593
浏览 649回答 1
1回答

慕标琳琳

你可以简单地做这样的事情(未经测试但应该有效):import h5pydef copy(dest, name):    g = dest.require_group(name)  # create output group with the name of input file    def callback(name, node):        if isinstance(node, h5py.Dataset):  # only copy dataset            g.create(name, data=node[:])with h5py.File('out.h5', 'w') as h5_out:    for f_in in files:        with h5py.File(f_in, 'r') as h5_in:                h5_in.visititems(copy(h5_out, f_in))这将为每个文件创建一个“文件夹”(HDF5 组)并递归复制所有内容。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python