1. 程式人生 > >TypeError: Object dtype dtype('O') has no native HDF5 equivalent

TypeError: Object dtype dtype('O') has no native HDF5 equivalent

想要將字典儲存為.h5檔案,出現了上面的問題,原因是h5py 不支援字典。
我這裡使用pickle 進行儲存,繞開了上面的問題:

import pickle as pkl
data = xxx
file = open('test.pkl','wb+')
pkl.dump(data, file)
file.close()

儲存之後讀取

  with open(path+'xxx.pkl', 'rb') as f:
    worddict = pkl.load(f)