通勤numpy稀疏矩阵点积 [英] Commute numpy sparse matrix dot product
问题描述
据我了解,numpy.sparse.csr_sparse.dot(other)
确实将other
乘以我的稀疏矩阵 :
To my understanding, numpy.sparse.csr_sparse.dot(other)
does multiply other
to my sparse matrix from the right:
A = numpy.sparse.csr_sparse(something)
B = numpy.matrix(something)
C = A.dot(B) # C = A*B
如何对两个矩阵求和以得到B*A
而又不失去将矩阵另存为稀疏矩阵(即.todense()
等)的好处?
How do I commute the two matrices to get B*A
without losing the benefits of saving my matrix as a sparse one (i.e. .todense()
etc.)?
推荐答案
关于矩阵乘法属性的一些复习:
A little refresher of matrix multiplication properties:
D = B * A
D.T = A.T * B.T
D = (A.T * B.T).T
这会导致显而易见的事情:
Which then leads to the obvious:
D = A.T.dot(B.T).T
请注意,CSR和CSC矩阵的换位非常快,因为它仅改变形状和类型(从CSR到CSC,或从CSC到CSR),而内部数据保持不变.
Note that transposition of CSR and CSC matrices is very fast, as it simply changes the shape and the type (from CSR to CSC, or from CSC to CSR), leaving the internal data unchanged.
这篇关于通勤numpy稀疏矩阵点积的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!