如何使用Python组合多个.h5文件(但形状相同)?
我有 10,000 个 3D 点云 .h5 文件。
它们具有相同的形状。
我想合并(或合并)2000 个文件,这样我总共可以有 5 个大 .h5 文件。 (比如python中的append()函数)
我从 h5py( http://docs.h5py.org/en/latest/high/group.html ) 中找到了 copy() 函数。
但是,我无法将该方法应用于我的问题。
请引用我的示例代码或帮助我解决我的问题。
抱歉我的英语水平不佳。
最佳答案
你可以简单地做这样的事情(未经测试但应该有效):
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 组),并递归地将所有内容复制到其中。
另请参阅:related question .
关于python - 如何使用 python 组合多个 .h5 文件(但形状相同)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52959371/