python - 在python中加载matlab稀疏矩阵(matlab v 7.3)

标签 python matlab matrix sparse-matrix h5py

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

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

最佳答案

正如您所猜测的,

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 示例。

关于python - 在python中加载matlab稀疏矩阵(matlab v 7.3),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19216574/

相关文章:

2个矩阵相加和相乘的C++程序

python - 如何从信号中获取频率?

matlab - 播放6 channel 音频Matlab

javascript - 在 JavaScript 中反序列化字典的 JSON 列表

c++ - 尺寸、长度换算?

matlab - matlab中搜索和删除单元格元素

python - 根据其索引初始化 NumPy 数组

c中的象棋矩阵

python pandas isin 方法?

python - 将 Python 侧模块从 Github 安装到 Anaconda