Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用python w/scipy读取MatLab文件_Python_Matlab_Scipy - Fatal编程技术网

用python w/scipy读取MatLab文件

用python w/scipy读取MatLab文件,python,matlab,scipy,Python,Matlab,Scipy,我正在使用python w/scipy包来读取MatLab文件 然而,这需要太长的时间和崩溃 数据大小约为50~MB 有没有更好的方法读取数据并形成边缘列表 我的python代码 import scipy.io as io data=io.loadmat('realitymining.mat') print data 我可以在解压缩后加载它。但它正在扩展记忆 当我尝试用倍频程加载它时,我得到: octave:1> load realitymining.mat error: memory

我正在使用python w/scipy包来读取MatLab文件

然而,这需要太长的时间和崩溃

数据大小约为50~MB

有没有更好的方法读取数据并形成边缘列表

我的python代码

import scipy.io as io
data=io.loadmat('realitymining.mat')
print data

我可以在解压缩后加载它。但它正在扩展记忆

当我尝试用
倍频程加载它时,我得到:

octave:1> load realitymining.mat
error: memory exhausted or requested size too large for range of Octave's index type -- trying to return to prompt
在伊皮顿

In [10]: data.keys()
Out[10]: ['network', 's', '__version__', '__header__', '__globals__']
In [14]: data['__header__']
Out[14]: 'MATLAB 5.0 MAT-file, Platform: MACI, Created on: Tue Sep 29 20:13:23 2009'
In [15]: data['s'].shape
Out[15]: (1, 106)
In [17]: data['s'].dtype
Out[17]: dtype([('comm', 'O'), ('charge', 'O'), ('active', 'O'), ('logtimes', 'O'),...  
   ('my_intros', 'O'), ('home_nights', 'O'), ('comm_local', 'O'), ('data_mat', 'O')])
# 58 fields
In [24]: data['s']['comm'][0,1].shape
Out[24]: (1, 30)
In [31]: data['s']['comm'][0,1][0,1]
Out[31]: ([[732338.8737731482]], [[355]], [[-1]], [u'Packet Data'], [u'Outgoing'], 
    [[40]], [[nan]])
In [33]: data['s']['comm'][0,1]['date']
Out[33]: 
array([[array([[ 732338.86915509]]), array([[ 732338.87377315]]),
    ...
    array([[ 732340.48579861]]), array([[ 732340.52778935]])]], dtype=object)
看看这些碎片。简单地尝试
打印数据
打印数据['s']
花费的时间太长。显然,它的结构太大,无法快速格式化


为了实际获取这些数据,我建议在Python或Matlab中加载一次,然后将有用的片段保存到一个或多个文件中。

也许您可以先处理部分数据,作为结构中的
网络,我已经使用Matlab将其解包


仍在研究如何整理剩余的大结构。

您可以将结构的每个字段保存在不同的文本文件中,例如:

save('friends.txt', '-struct', 'network', 'friends', '-ascii')
并分别从python加载每个文件

friends = numpy.loadtxt('friends.txt')

立即加载。

无错误。只是这需要很多时间。你的问题是“它崩溃了”。文件是如何创建的?你能把它贴在什么地方吗?只是将来的一个建议:对大型数据集使用HDF5。Matlab提供了对它的支持函数,Python提供了Pytable形式的强大支持。