如何在Python中将稀疏矩阵从.mat文件转换为密集矩阵? 导入xlrd、xlwt 将scipy作为sp导入 导入scipy.io 作为pd进口熊猫 将matplotlib.pyplot作为plt导入 进口派拉布 从scipy.sparse导入csc_矩阵 %matplotlib内联 FileString=r'/content/drive/MyDrive/Thesis/EXIOBASE\u 3rx\u aggregatanduseExtensions\u 2015\u pxp.mat' MRIO=scipy.io.loadmat(文件字符串) 地区=MRIO['IO']['A'] 在:区域 输出:数组([]], 数据类型=对象) 在:Regions.todense()中 输出: AttributeError回溯(最近一次呼叫上次) 在() ---->1.todense()地区 AttributeError:'numpy.ndarray'对象没有属性'todense'

如何在Python中将稀疏矩阵从.mat文件转换为密集矩阵? 导入xlrd、xlwt 将scipy作为sp导入 导入scipy.io 作为pd进口熊猫 将matplotlib.pyplot作为plt导入 进口派拉布 从scipy.sparse导入csc_矩阵 %matplotlib内联 FileString=r'/content/drive/MyDrive/Thesis/EXIOBASE\u 3rx\u aggregatanduseExtensions\u 2015\u pxp.mat' MRIO=scipy.io.loadmat(文件字符串) 地区=MRIO['IO']['A'] 在:区域 输出:数组([]], 数据类型=对象) 在:Regions.todense()中 输出: AttributeError回溯(最近一次呼叫上次) 在() ---->1.todense()地区 AttributeError:'numpy.ndarray'对象没有属性'todense',python,matlab,scipy,sparse-file,Python,Matlab,Scipy,Sparse File,我试图将这个稀疏矩阵从MATLAB文件转换为密集矩阵,因此我应用了todense()函数,但我不知道为什么它不起作用。非常感谢你的帮助 谢谢您需要打开包装: import xlrd, xlwt import scipy as sp import scipy.io import pandas as pd import matplotlib.pyplot as plt import pylab from scipy.sparse import csc_matrix %matplotlib inlin

我试图将这个稀疏矩阵从MATLAB文件转换为密集矩阵,因此我应用了todense()函数,但我不知道为什么它不起作用。非常感谢你的帮助 谢谢

您需要打开包装:

import xlrd, xlwt
import scipy as sp
import scipy.io
import pandas as pd
import matplotlib.pyplot as plt
import pylab
from scipy.sparse import csc_matrix
%matplotlib inline

FileString = r'/content/drive/MyDrive/Thesis/EXIOBASE_3rx_aggLandUseExtensions_2015_pxp.mat'
MRIO = scipy.io.loadmat(FileString)

Regions = MRIO['IO']['A']

IN: Regions
OUT: array([[<42800x42800 sparse matrix of type '<class 'numpy.float64'>'
    with 5986549 stored elements in Compressed Sparse Column format>]],
      dtype=object)

IN: Regions.todense()
OUT: 
AttributeError                            Traceback (most recent call last)
<ipython-input-116-3ef413dd7ae9> in <module>()
----> 1 Regions.todense()

AttributeError: 'numpy.ndarray' object has no attribute 'todense'
应该有用

我建议先展示一下

x[0,0].todense()
x[0,0].A        # for array

我怀疑在MATLAB中这是一个
单元
,大小为(1,1)
loadmat
自由地使用
对象
dtype数组来保存MATLAB
单元格
struct
。只有纯矩阵才能变成数字数组。

非常感谢您的建议,在MATLAB中它是“42800x42800稀疏双精度”
x[0,0].todense()
x[0,0].A        # for array
 x[0,0]