为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

慕妹3146593 2021-07-22 18:01:21
如何使用python组合多个.h5文件(但形状相同)?我有 10,000 个 .h5 文件用于 3D 点云。它们具有相同的形状。我想合并(或合并)2000 个文件,所以我总共可以有 5 个大的 .h5 文件。(比如python中的append()函数)我从 h5py( http://docs.h5py.org/en/latest/high/group.html ) 中找到了 copy() 函数。但是,我无法将这种方法应用于我的问题。请参考我的示例代码或帮助我解决我的问题。
查看完整描述

1 回答

?
慕标琳琳

TA贡献1830条经验 获得超9个赞

你可以简单地做这样的事情(未经测试但应该有效):


import h5py


def 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 组)并递归复制所有内容。


查看完整回答
反对 回复 2021-07-28
  • 1 回答
  • 0 关注
  • 648 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号