csr_matrix
来源:互联网 发布:怎么查看服务器域名 编辑:程序博客网 时间:2024/06/05 02:11
csr_matrix
>>> indptr = np.array([0, 2, 3, 6])>>> indices = np.array([0, 2, 2, 0, 1, 2])>>> data = np.array([1, 2, 3, 4, 5, 6])>>> csr_matrix((data, indices, indptr), shape=(3, 3)).toarray()array([[1, 0, 2], [0, 0, 3], [4, 5, 6]])# 按row行来压缩# 对于第i行,列是indices[indptr[i]:indptr[i+1]] 数据是data[indptr[i]:indptr[i+1]]# 在本例中# 第0行,有非0的数据列是indices[indptr[0]:indptr[1]] = indices[0,2] = [0,2]# 数据是data[indptr[0]:indptr[1]] = data[0,2] = [1,2],所以在第0行第0列是1,第2列是2# 第1行,有非0的数据列是indices[indptr[1]:indptr[2]] = indices[2,3] = [2]# 数据是data[indptr[1]:indptr[2] = data[2,3] = [3],所以在第1行第2列是3# 第2行,有非0的数据列是indices[indptr[2]:indptr[3]] = indices[3,6] = [0,1,2]# 数据是data[indptr[2]:indptr[3]] = data[3,6] = [4,5,6],所以在第2行第0列是4,第1列是5,第2列是6
(注:论文的行下标和列下标均从0开始)
data 表示 元数据 显然为1, 2, 3, 4, 5, 6
shape 表示 矩阵的形状 为 3 * 3
indices 表示 各个数据在各行的下标, 从该数据我们可以知道:数据1在某行的0位置处, 数据2在某行的2位置处,6在某行的2位置处。
而各个数据在哪一行就要通过indptr参数得到的
indptr 表示每行数据的个数:[0 2 3 6]表示从第0行开始数据的个数,0表示默认起始点,0之后有几个数字就表示有几行,第一个数字2表示第一行有2 - 0 = 2个数字,因而数字1,2都第0行,第二行有3 - 2 = 1个数字,因而数字3在第1行,以此类推,我们能够知道所有数字的行号
Example: 数字6 ,indptr推出在第2行,indices推出在第2列。
Numpy文件存取
http://blog.csdn.net/sherrylml/article/details/51494052
阅读全文
0 0
- csr_matrix
- csr_matrix矩阵
- csr_matrix参数解析
- csr_matrix计算tf
- Save / load scipy array,sparse csr_matrix
- scipy csr_matrix和csc_matrix函数详解
- scipy csr_matrix和csc_matrix函数详解
- sparse.csr_matrix矩阵的压缩存储
- 利用scipy.sparse.csr_matrix构建term-document矩阵
- csr_matrix(Compressed Sparse Row matrix)存储模式浅析
- scipy.sparse中csc_martrix和csr_matrix两个稀疏矩阵的区别
- 中国剩余定理证明
- QT程序与html交互(三)------QT WebChannel JavaScript API
- 广搜之抓住那头牛
- 数据结构与算法1:数组1
- Failed to resolve: com.tencent.mm.opensdk:wechat-sdk-android-with-mta:+
- csr_matrix
- SQLAlchemy_定义(一对一/一对多/多对多)关系
- [转]一个中高级PHP工程师所应该具备的能力
- 树形索引(B-树查找、插入、删除)
- 文章标题
- my idea about visitor pattern
- Linux下GCC编译器链接任意目录下库文件(解决错误“/usr/bin/ld: cannot find -lxxx”)
- xml编写通讯录(xml的增删改查)
- linux修改用户密码,创建用户组,将用户加入用户组