python序列化(数据本地存放持久性存储)和反序列化

http://blog.csdn.net/uestcyao/article/details/7874817
 1 #读取图片并存储为矩阵
 2 from scipy.misc import imread
 3 im = imread("/Users/NaCl/Documents/GitHub/test.png")
 4 
 5 #将读取到的矩阵数据序列化、即进行持久性存储
 6 from numpy import *
 7 import pickle
 8 
 9 with open('test.pickle', 'wb') as f:
10     pickle.dump(im, f)   
11 
12 #将数据进行反序列化
13 with open('/Users/NaCl/Documents/GitHub/test.pickle', 'rb') as f:
14     f = pickle.load(f)
15     print type(f)
16     print f.shape
17     

 

 

 

posted @ 2015-12-10 11:58  视觉书虫  阅读(553)  评论(0编辑  收藏  举报