概述
在用python进行科学运算时,常常需要把一个稀疏的np.array压缩,这时候就用到scipy库中的sparse.csr_matrix(csr:Compressed Sparse Row...indices, indptr), shape=(3, 3)).toarray()
array([[1, 0, 2],
[0, 0, 3],
[4, 5, 6]])
注:矩阵下标为...其中:indptr参数,0表示默认起始点,0之后有几个数字就表示有几行
data 表示 元数据 显然为1, 2, 3, 4, 5, 6
shape 表示 矩阵的形状 为 3 * 3
indices...indices, indptr), shape=(3, 3)).toarray()
array([[1, 0, 4],
[0, 0, 5],
[2, 3, 6]])
# 按col列来压缩