Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reading MatLab files in python w/ scipy

I'm using python w/ scipy package to read the MatLab file.

However it takes too long and crashes.

The Dataset is about 50~ MB in size

Is there any better way to read the data and form an edge list ?

My python code

import scipy.io as io
data=io.loadmat('realitymining.mat')
print data
like image 411
Abhishek Kannan Avatar asked Dec 13 '13 18:12

Abhishek Kannan


People also ask

Can I load .MAT file in Python?

By default, Python is not capable of reading . mat files.

How do I open a MATLAB file without MATLAB?

Opening the Editor Without Starting MATLAB On Windows platforms, you can use the MATLAB Editor without starting MATLAB. To do so, double-click an M-file in Windows Explorer. The M-file opens in the MATLAB Editor. To open the Editor without a file, open $matlabroot/bin/win32/meditor.exe .

How do I use .MAT files?

To load saved variables from a MAT-file into your workspace, double-click the MAT-file in the Current Folder browser. To load a subset of variables from a MAT-file on the Home tab, in the Variable section, click Import Data.

How do I read a .MAT file in MATLAB?

load( filename ) loads data from filename . If filename is a MAT-file, then load(filename) loads variables in the MAT-file into the MATLAB® workspace. If filename is an ASCII file, then load(filename) creates a double-precision array containing data from the file.


1 Answers

You could just save each field of the struct in a different text file, eg:

save('friends.txt', '-struct', 'network', 'friends', '-ascii')

and load each file separately from python

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

which loads instantly.

like image 164
blue_note Avatar answered Sep 28 '22 12:09

blue_note