📅  最后修改于: 2022-03-11 14:45:42.049000             🧑  作者: Mango
import time
import numpy as np
import h5py
import os
arr = np.random.randn(1000)
with h5py.File('groups.hdf5', 'w') as f:
g = f.create_group('Base_Group')
d = g.create_dataset('default', data=arr)
g.attrs['Date'] = time.time()
g.attrs['User'] = 'Me'
d.attrs['OS'] = os.name
for k in g.attrs.keys():
print('{} => {}'.format(k, g.attrs[k]))
for j in d.attrs.keys():
print('{} => {}'.format(j, d.attrs[j]))