以t2vec的 data/porto-vocab-dist-cell100.h5 为例
import h5py
import numpy as np
data_dir='/home/ruizhichai/t2vec/data/porto-vocab-dist-cell100.h5'
file=h5py.File(data_dir,'r')
#打开文件
file.keys()
#
file.visit(lambda x: print(x))
'''
D
V
'''
file['D'][:].shape,file['D'][:]
'''
((18866, 10),
array([[ 0. , 0. , 0. , ..., 0. ,
0. , 0. ],
[ 0. , 0. , 0. , ..., 0. ,
0. , 0. ],
[ 0. , 0. , 0. , ..., 0. ,
0. , 0. ],
...,
[ 412.31056256, 400. , 316.22776602, ..., 223.60679775,
141.42135624, 200. ],
[1486.60687473, 1389.24439894, 1476.48230602, ..., 447.2135955 ,
100. , 0. ],
[ 761.57731059, 707.10678119, 670.82039325, ..., 100. ,
0. , 200. ]]))
'''
data_dir='tst.h5'
file=h5py.File(data_dir,'w')
grp_1=file.create_group('group_1')
grp_2=file.create_group('group_2')
lst1=np.arange(10)
lst2=np.arange(5,8)
lst3=np.arange(6,10,2)
grp_1.create_dataset("lst1",data=lst1)
grp_2.create_dataset("lst2",data=lst2)
file.create_dataset("lst3",data=lst3)
file.keys()
#
file['group_1'].keys()
#
file['group_1']['lst1'][:]
#array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])