python保存字典和读取字典pickle
Posted C~K
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python保存字典和读取字典pickle相关的知识,希望对你有一定的参考价值。
import pickle import numpy as np def save_obj(obj, name): with open(name + ‘.pkl‘, ‘wb‘) as f: pickle.dump(obj, f, pickle.HIGHEST_PROTOCOL) def load_obj(name): with open(name + ‘.pkl‘, ‘rb‘) as f: return pickle.load(f) a = load_obj(‘logistic_regression_res‘) W = np.array(a[‘W‘]) b = np.array(a[‘b‘]) print(W) print(b)
以上是关于python保存字典和读取字典pickle的主要内容,如果未能解决你的问题,请参考以下文章