简体   繁体   English

Python scipy.sparse.csr_marix 到 Matlab 等效项

[英]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.我正在阅读一篇论文,但他们的代码是用 python 编写的,所以我决定将其转换为 Matlab 代码以适应我的工作。 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注意:变量 D、R 和 C 是派生自的数组/矩阵

    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.我只是不知道 sparse.csr_matrix(D,(R,C) 是什么意思以及它的 Matlab 等价物是什么。

DC and R stand for Data, Column and Row . DC 和 R 代表数据、列和行 It is passing the nonzero elements to create a sparse matrix.它传递非零元素以创建稀疏矩阵。 This is very close to the MATLAB-Syntax S = sparse(i,j,v)这非常接近 MATLAB 语法S = sparse(i,j,v)

  • i is the row index, corresponding to R i 是行索引,对应于 R
  • j is the column index, corresponding to C j为列索引,对应C
  • v is the Value, corresponding to D v 是值,对应于 D

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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