Reputation: 567
I have a data file storing a large matlab sparse matrix (matlab 7.3) that needs to be used in my python program. I use h5py to load this sparse matrix and find there are 3 data structures associated with the sparse matrix.
Suppose the name of the sparse matrix is M and the 3 data structures are M['data'], M['ir'], M['jc']. Initially I thought M['ir'] and M['jc'] store the row indices and column indices for nonzero items, but I have just found that there exist some values in M['jc'] larger than the row number of the sparse matrix. Can anyone explain what kinds of information are stored in the 3 data structure?
Upvotes: 2
Views: 643
Reputation: 9696
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.
Upvotes: 2