scipy csc csr到底是什么東西
來源:程序員人生 發布時間:2014-12-22 08:32:41 閱讀次數:3040次
哎,真尼瑪,網上關于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這3個數在矩陣里的行數,那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的,關于這有1個更好的例子:
csparse
大家如果對這個還不清楚,我這個曾深受其害的人愿意提供更多解答。
生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈