【问题标题】:Exporting a Scipy sparse matrix from Python2.7 to Matlab?将 Scipy 稀疏矩阵从 Python2.7 导出到 Matlab?
【发布时间】:2014-02-08 11:32:49
【问题描述】:

我有一个非常大的 Scipy 稀疏 (csr) 矩阵。我不能使用M.toarray(),因为它会触发ValueError: array is too big. 有没有办法在Python 中保存一个Scipy 稀疏矩阵以便在Matlab 中读取?我需要一些 Matlab 中可用的工具。

【问题讨论】:

    标签: python matlab scipy sparse-matrix mat-file


    【解决方案1】:

    Scipy 的 Mat 文件格式工具支持稀疏矩阵:

    from scipy import sparse, io
    m = sparse.rand(50000,50000,density=1e-8)
    io.savemat('dump.mat', dict(m=m))
    

    在matlab中:

    >> load dump
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-03-31
      • 2013-11-13
      • 2017-03-26
      • 1970-01-01
      • 2023-04-10
      • 1970-01-01
      • 2014-11-01
      • 1970-01-01
      相关资源
      最近更新 更多