dict 保存 數組

 # 保存字典
    with open('E:/AApaper/Model/cnn/'+'vocab.json','a') as outfile:
        json.dump(vocab,outfile,ensure_ascii=True)
        outfile.write('\n')
    with open('E:/AApaper/Model/cnn/'+'vocab.json', encoding='utf-8') as f:
        line = f.readline()
        vocab = json.loads(line)
        f.close()
    print(vocab)
#列表保存 
np.savetxt(path+'myVocabList.txt', myVocabList,fmt="%s", delimiter=",")
p0V, p1V, pAb = trainNB0(array(trainMat), array(listClasses))
#以逗號分隔保存二維數組
np.savetxt(path + 'p0V.txt', p0V, delimiter=",")
多維數pAb是數組,把數組存放到另一個數組中
pAbarray[0]=pAb
np.savetxt(path + 'pAb.txt', pAbarray)

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章