关于第一个元组代表什么,我有点困惑 . 它是稀疏数组的索引和值吗?例如
In [4]: arrays=(np.array([0, 1, 2], dtype=int), np.array([2, 0, 0], dtype=int), np.array([2, 1, 3], dtype=float))
...
In [6]: from scipy import sparse
In [7]: M=sparse.csr_matrix((arrays[2],(arrays[0],arrays[1])))
In [8]: M
Out[8]:
<3x3 sparse matrix of type ''
with 3 stored elements in Compressed Sparse Row format>
In [9]: M.A
Out[9]:
array([[ 0., 0., 2.],
[ 1., 0., 0.],
[ 3., 0., 0.]])
In [10]: print(M)
(0, 2) 2.0
(1, 0) 1.0
(2, 0) 3.0
矩阵乘法是为这样的数组定义的:
In [12]: M*M.T
Out[12]:
<3x3 sparse matrix of type ''
with 5 stored elements in Compressed Sparse Row format>
In [13]: (M*M.T).A
Out[13]:
array([[ 4., 0., 0.],
[ 0., 1.