0

i'm looking for an equivalent to this python 3.6 code :

import scipy.io as sio
file = sio.loadmat('file.mat')
data = file['data']

I have to do the same thing in python 2.7, i tryed

import h5py
f = h5py.File('file.mat')

But it doesn't work, do you have an idea?

Thank you

1 Answers1

0

If you don't want to use scipy, you can use h5py. It support Matlab arrays saved as v3.7 arrays.

import numpy as np
import h5py 

f = h5py.File('file.mat','r') 
data = f.get('data/variable_name') 

# convert to numpy array
data = np.array(data)

Save the data from Matlab like so save('filename', '-v7.3', 'var1');

rinkert
  • 6,593
  • 2
  • 12
  • 31