2013-10-07 52 views
1

我有一个数据文件存储需要在我的python程序中使用的大型matlab稀疏矩阵(matlab 7.3)。我使用h5py加载这个稀疏矩阵,并发现有3个数据结构与稀疏矩阵相关联。假设稀疏矩阵的名称为M,三种数据结构为M ['data'],M ['ir'],M ['jc']。起初,我认为M ['ir']和M ['jc']存储非零项的行索引和列索引,但我刚刚发现在M ['jc']中存在一些大于行数稀疏矩阵。任何人都可以解释什么样的信息存储在3数据结构中?在python中加载matlab稀疏矩阵(matlab v 7.3)

回答

2

ir就像你猜测的那样,是非空行的行索引。对于列索引,事情有点复杂,但在Mathworks mex-Function文档中完整记录。

http://www.mathworks.de/de/help/matlab/apiref/mxsetir.html粘贴:

If the jth column of the sparse mxArray has any nonzero elements: 

jc[j] is the index in ir, pr, and pi (if it exists) of the first nonzero element in the jth column. 
jc[j+1]-1 is the index of the last nonzero element in the jth column. 
For the jth column of the sparse matrix, jc[j] is the total number of nonzero elements in all preceding columns. 
The number of nonzero elements in the jth column of the sparse mxArray is: 

jc[j+1] - jc[j]; 

还要检查mxSetIr的机制的文档。 假设您也可以访问matlab,您应该检查从文档链接的mex示例。

+0

非常感谢您的回答。 – hanqiang