In python with numpy, let's say I have two matrices:
Ssparse matrix x*xMdense matrix x*y
Now I want to do np.dot(M, M.T)which will return a dense matrix x*x S_.
However, I don’t care that the cells are non-zero in S, which means that this will not affect my application if I did
S_ = S*S_
Obviously, this would be a waste of operations, since I would like to leave all the inappropriate cells listed in Salltogether. Remember that when multiplying the matrix
S_[i,j] = np.sum(M[i,:]*M[:,j])
So, I want to do this operation only i,jto S[i,j]=True.
Is this supported in some way with numpy implementations that run in C, so that I don't need to implement it with python loops?
EDIT: I still have this problem, actually Mnow also sparse.
Now, if rows and columns are given S, I implemented it as follows:
data = np.array([ M[rows[i],:].dot(M[cols[i],:]).data[0] for i in xrange(len(rows)) ])
S_ = csr( (data, (rows,cols)) )
... but he is still slow. Any new ideas?