标签:view col one class special 存储 pre lda nump
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()
标签:view col one class special 存储 pre lda nump
原文地址:https://www.cnblogs.com/dolphin-bamboo/p/10294880.html