scipy csc csr到底是什么东西

哎,真尼玛,网上关于scipy 和 theano的 sparse matrix中的 csc matrix 和 csr matrix太少了,有,也只是使用,并没有说明,那个矩阵是怎么生成的。参考例子:
>>> data = np.asarray([7, 8, 9])
>>> indices = np.asarray([0, 1, 2])
>>> indptr = np.asarray([0, 2, 3, 3])
>>> m = sp.csc_matrix((data, indices, indptr), shape=(3, 3))
>>> print m.toarray()
[[7 0 0]
 [8 0 0]
 [0 9 0]]

这里面indices 还好说,就是非零数据7,8,9这三个数在矩阵里的行数,那inptr是什么鬼玩意,其全拼是 index pointer array。根本不知道干什么用的,最终原来是这样的,我们还以上面的例子为例:

data:      7     8      9

indices:0      1      2

indptr:   0              2      3    3

就是说7和8是0列的,9是1列的。7在0列0行上,8在0列1行上,9在1列2行上,其余元素全部为0,这样就形成了

[7 0 0]
 [8 0 0]
 [0 9 0]]
其实这是源于csparse的,关于这有一个更好的例子: csparse

大家如果对这个还不清楚,我这个曾经深受其害的人愿意提供更多解答。





你可能感兴趣的:(scipy,CSR,CSC,theano)