版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/NockinOnHeavensDoor/article/details/83684713
例子:
from scipy import sparse
data = np.array([1, 4, 5, 2, 3, 6])
indices = np.array([0, 2, 2, 0, 1, 2])
indptr = np.array([0, 2, 3, 6])
mtx = sparse.csr_matrix((data, indices, indptr), shape=(3, 3))
结果:
matrix([[1, 0, 4],
[0, 0, 5],
[2, 3, 6]])
- indptr[0] = 0 、indptr[1]=2,所以有indices[0:2]=0,2,则第一行的位置0、2对应data中的1、4;
- 以此类推,indptr[1]=2 、 indptr[2]=3, indices[2:3]=2,则第二行的位置2处对应data中的5.
- 。。。。