h5py

import h5py
def print_attrs(name, obj):
print(name,'--name')
if isinstance(obj, h5py.Dataset):
print(" shape:", obj.shape)
print(" dtype:", obj.dtype)
else:
for key, val in obj.attrs.items():
print(" %s: %s" % (key, val))
def traverse_hdf5(f):
for key in f.keys():
print_attrs(key, f[key])
if isinstance(f[key], h5py.Group):
traverse_hdf5(f[key])
with h5py.File('channels-7.h5', 'r') as f:
traverse_hdf5(f)
import h5py
def print_attrs(name, obj):
print(name,'--name')
if isinstance(obj, h5py.Dataset):
print(" shape:", obj.shape)
print(" dtype:", obj.dtype)
else:
for key, val in obj.attrs.items():
print(" %s: %s" % (key, val))
def traverse_hdf5(f):
for key in f.keys():
print_attrs(key, f[key])
if isinstance(f[key], h5py.Group):
traverse_hdf5(f[key])
with h5py.File('channels-7.h5', 'r') as f:
traverse_hdf5(f)
这段代码展示了如何使用h5py库在Python中遍历HDF5文件的各个节点,包括打印Dataset的shape和dtype属性,以及Group的attributes。
1586

被折叠的 条评论
为什么被折叠?



