【发布时间】:2012-08-27 14:32:53
【问题描述】:
如果你有一个稀疏矩阵 X:
>> X = csr_matrix([[0,2,0,2],[0,2,0,1]])
>> print type(X)
>> print X.todense()
<class 'scipy.sparse.csr.csr_matrix'>
[[0 2 0 2]
[0 2 0 1]]
还有一个矩阵Y:
>> print type(Y)
>> print text_scores
<class 'numpy.matrixlib.defmatrix.matrix'>
[[8]
[5]]
...如何将 X 的每个元素乘以 Y 的行数。例如:
[[0*8 2*8 0*8 2*8]
[0*5 2*5 0*5 1*5]]
或:
[[0 16 0 16]
[0 10 0 5]]
我已经厌倦了这个,但显然它不起作用,因为尺寸不匹配:
Z = X.data * Y
【问题讨论】:
标签: python matrix numpy scipy sparse-matrix