Save / load scipy array,sparse csr_matrix
2016-02-23 09:58
405 查看
A csr_matrix has 3 data attributes that matter:
and
All are simple ndarrays, so
work on them. Save the three arrays with
load them back with
and then recreate the sparse matrix object with:
def save_sparse_csr(filename,array):
np.savez(filename,data = array.data ,indices=array.indices,indptr =array.indptr, shape=array.shape )
def load_sparse_csr(npzfilename):
loader = np.load(npzfilename)
return csr_matrix(( loader['data'], loader['indices'], loader['indptr']),shape = loader['shape'])
def save_ids_array(filename,array):
np.savez(filename+'.ids',data = array)
def load_ids_array(npzfilename):
loader = np.load(npzfilename)
return loader['data']
.data,
.indices,
and
.indptr.
All are simple ndarrays, so
numpy.savewill
work on them. Save the three arrays with
numpy.saveor
numpy.savez,
load them back with
numpy.load,
and then recreate the sparse matrix object with:
new_csr = csr_matrix((data, indices, indptr), shape=(M, N))
def save_sparse_csr(filename,array):
np.savez(filename,data = array.data ,indices=array.indices,indptr =array.indptr, shape=array.shape )
def load_sparse_csr(npzfilename):
loader = np.load(npzfilename)
return csr_matrix(( loader['data'], loader['indices'], loader['indptr']),shape = loader['shape'])
def save_ids_array(filename,array):
np.savez(filename+'.ids',data = array)
def load_ids_array(npzfilename):
loader = np.load(npzfilename)
return loader['data']
相关文章推荐
- 网站地图 django静态文件访问 php文件上传 2016.02.23回顾
- iOS开发时间戳与时间,时区的转换,汉字与UTF8,16进制的转换
- Yii2.0数据库查询实例(三)
- NPY and girls-HDU5145莫队算法
- CodeForces 629D Babaei and Birthday Cake
- iOS开发常遇错误之Xcode编译Undefined symbols for architecture xxx 错误总结
- 1058: [ZJOI2007]报表统计 set+map+priority_queue
- 页面响应时间计算
- Linux笔记(15)——管道符
- 浪子回头金不换:学软件开发找到人生春天
- javascript每日必学之封装
- HashTable、HashSet和Dictionary的区别
- java 图片质量压缩
- 我是这样克服拖延症的,你也可以试试
- UVA1593 不定量不定长度单词,左对齐
- 博客目录
- C#ReadLine()和ReadKey()区别
- RequireJS入门(一)
- 谷歌坐标系转换
- jQuery常用知识点总结以及平时封装常用函数