H5py文件
Posted dolphin-bamboo
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了H5py文件相关的知识,希望对你有一定的参考价值。
h5py---字符串存储
import h5py import numpy as np h = h5py.File(‘capsule_box.h5‘, ‘w‘) #print(h[‘user1img1‘][:]) dt = h5py.special_dtype(vlen=str) with open(‘train-2000-capsul‘) as f: for lin in f: lines = lin.split() convert = lines[3:] a = np.array(convert) print(a) ds = h.create_dataset(‘user‘+str(lines[0])+‘img‘+str(lines[1]), a.shape, dtype=dt) ds[:] = a h.close()
4.用h5py存储文件(数字字符)--example
import h5py import numpy as np f = h5py.File(‘C:\Users\My\Desktop\h5\data_box.h5‘, ‘w‘) with open(‘H:\datasets_object\box-encode-allData.trainingPair‘) as fr: for lin in fr: lines = lin.split() convert = lines[3:] converts = ‘ ‘.join(convert) x = np.fromstring(converts, dtype=np.uint8).astype(‘float64‘) # 写进h5 name = ‘user‘+lines[0]+‘img‘+lines[1] print(name) f.create_dataset(name, data=x) f.close()
以上是关于H5py文件的主要内容,如果未能解决你的问题,请参考以下文章