矩阵中行和列的点积是1x1csr_matrix
。如何有效地将其转换为标量?现在我使用sum
。M
下面是一个方阵:
dot_product_result = csr_matrix.sum(M.getrow(3).dot(M.getcol(5)))
更新当我尝试下面的解决方案时,我得到以下错误:
^{pr2}$这是我实际使用的代码:
e = rating - Q.getrow(mid).dot(P.getcol(uid))[0]
iteration_error += e
我将iteration_error
初始化为0.0。在
M[3,:].dot(M[:,5])[0,0]
同样,像这样调用
csr_matrix.sum
不是很好的风格:它是一个实例方法,所以应该称为M[3,:].dot(M[:,5]).sum()
相关问题 更多 >
编程相关推荐