【问题标题】:loading matlab sparse matrix (matlab v 7.3) in python在python中加载matlab稀疏矩阵(matlab v 7.3)
【发布时间】:2013-10-07 03:18:39
【问题描述】:

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

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

【问题讨论】:

    标签: python matlab matrix sparse-matrix h5py


    【解决方案1】:

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

    【讨论】:

    • 非常感谢您的回答。
    猜你喜欢
    • 2012-01-16
    • 2022-08-18
    • 2013-04-11
    • 1970-01-01
    • 2014-11-01
    • 2014-05-12
    • 1970-01-01
    • 2012-04-02
    • 1970-01-01
    相关资源
    最近更新 更多