简体   繁体   中英

Python scipy.sparse.csr_marix to Matlab Equivalent

I'm reading a paper but their code is in python so I decided to convert it to Matlab code to adapt with my work. However, there is this little block of code that I don't understand.

  S = scipy.sparse.csr_matrix((D, (R, C)), shape=(r, old_dim))
  MSt = scipy.sparse.csr_matrix.dot(M, S.T)

Could anyone please explain what they are trying to do here? what does the above line mean? NB: the variables D, R and C are arrays/matrices derived from

    C = np.arange(old_dim)
    R = np.random.random_integers(r, size=old_dim) - 1
    D = np.random.randint(2, size=old_dim) * 2 - 1
     % also r and old_dim are dimension sizes e.g 5 or 10

I understand this part. I just don't know what sparse.csr_matrix(D,(R,C) means and what could be its Matlab equivalent.

DC and R stand for Data, Column and Row . It is passing the nonzero elements to create a sparse matrix. This is very close to the MATLAB-Syntax S = sparse(i,j,v)

  • i is the row index, corresponding to R
  • j is the column index, corresponding to C
  • v is the Value, corresponding to D

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM