本文共 1412 字,大约阅读时间需要 4 分钟。
pip install h5py
安装完成后,可以通过导入库来验证是否成功:
import h5py print("h5py库安装成功!") import h5py import numpy as np with h5py.File('example.h5', 'w') as f: dset = f.create_dataset('dataset', data=np.arange(100)) print("HDF5文件已创建并写入数据。") import h5py import numpy as np with h5py.File('example.h5', 'r') as f: dset = f['dataset'] print(dset) print(f"数据集的形状为:{dset.shape}") import h5py import numpy as np with h5py.File('multi_dataset.h5', 'w') as f: # 创建一维数组 arr = np.arange(10) f.create_dataset('one_dim', data=arr) # 创建二维数组 arr2 = np.arange(10).reshape(5,2) f.create_dataset('two_dim', data=arr2) # 创建群组(Group) group = f.create_group('root_group', 'group_1') # 在群组下创建三维数组 arr3 = np.arange(15).reshape(3,5) group.create_dataset('three_dim', data=arr3) print("多层次数据集已成功创建。") 转载地址:http://hwofk.baihongyu.com/