我是一个有用的助手,可以为您进行文本翻译。
我有一个稀疏矩阵A(在密集形式下等于10 * 3),例如:
print type(A)
<class scipy.sparse.csr.csr_matrix>
print A
(0, 0) 0.0160478743808
(0, 2) 0.0317314165078
(1, 2) 0.0156596521648
(1, 0) 0.0575683686558
(2, 2) 0.0107481166871
(3, 0) 0.0150580924929
(3, 2) 0.0297743235876
(4, 0) 0.0161931803955
(4, 2) 0.0320187296788
(5, 2) 0.0106034409766
(5, 0) 0.0128109177074
(6, 2) 0.0105766993238
(6, 0) 0.0127786088452
(7, 2) 0.00926522256063
(7, 0) 0.0111941023699
每列的最大值为:
print A.max(axis=0)
(0, 0) 0.0575683686558
(0, 2) 0.0320187296788
I would like to get the index corresponding to the column value. I know that the
A.getcol(i).tolist()
will return me a list of each column which allow me to use argmax() function, but this way is really slow. I am wondering is there any descent way to do?
A.todense()
是可行的,执行A.todense().argmax(axis=0)
会得到你想要的结果。 - kbroseargmax
对于 scipy 稀疏矩阵来说是一个不错的增强功能。同时,您能否切换到 CSC 格式?如果可以的话,有一种相当高效的方法来获取列的 argmax。 - Warren Weckesser