2

我有一个存储需要在我的 python 程序中使用的大型 matlab 稀疏矩阵(matlab 7.3)的数据文件。我使用 h5py 加载这个稀疏矩阵,发现有 3 个数据结构与稀疏矩阵相关联。

假设稀疏矩阵的名字是M,3个数据结构是M['data'], M['ir'], M['jc']。最初我认为 M['ir'] 和 M['jc'] 存储非零项的行索引和列索引,但我刚刚发现 M['jc'] 中存在一些大于行数的值稀疏矩阵。谁能解释一下 3 数据结构中存储了哪些类型的信息?

4

1 回答 1

2

ir is, as you guessed, the row-index of non-empty rows. For the column-index things are somewhat more complicated but fully documented in Mathworks mex-Function documentation.

Pasted from 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];

Also check the documention on mxSetIr. Assuming you also have access to matlab, you should probably check the mex examples linked from the docs.

于 2013-10-07T07:31:56.940 回答