2013-12-13 11 views
8

Utilizzo il pacchetto python w/scipy per leggere il file MatLab.Lettura di file MatLab in python w/scipy

Tuttavia, ci vuole troppo tempo e si blocca.

Il Dataset è di circa 50 ~ MB

C'è un modo migliore per leggere i dati e formare una lista di bordo?

Il mio codice python

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

Quale messaggio di errore? – Daniel

+0

Nessun errore. Solo che ci vuole un sacco di tempo. –

+2

La tua domanda dice "si blocca". – Daniel

risposta

0

posso caricarlo dopo aver decompresso. Ma sta estendendo la memoria.

quando provo a caricarlo con octave ottengo:

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 ipython

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) 

Guarda i pezzi. Semplicemente provando a print data o print data['s'] ci vuole troppo tempo. Apparentemente è troppo grande di struttura per formattare rapidamente.

Per ottenere praticamente questi dati, suggerisco di caricarli una volta in Python o Matlab e quindi salvare i pezzi utili in uno o più file.

0

Forse è possibile prima lavorare su parte dei dati come lo network nella struttura, l'ho spacchettato here utilizzando MATLAB.

Ancora lavorando su come riordinare il resto della struttura più grande.

1

Si potrebbe semplicemente salvare ogni campo della struct in un file di testo diverso, ad esempio:

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

e caricare ogni file separatamente in pitone

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

che carica immediatamente.