I have a set of MAT-files which contains a matlab struct. The struct has bunch of arrays. I would like to open the file and transfer all of them into arrays. So far I have written the following code:
import h5py
>>> fs = h5py.File('statistics_VAD.mat','r')
>>> list(fs.keys())
['#refs#', 'data']
>>>
>>> fs['data'].visititems(lambda n,o:print(n, o))
C <HDF5 dataset "C": shape (100, 1), type "|O">
P <HDF5 dataset "P": shape (100, 1), type "|O">
V <HDF5 dataset "V": shape (100, 1), type "|O">
Wn <HDF5 dataset "Wn": shape (100, 1), type "|O">
X <HDF5 dataset "X": shape (100, 1), type "|O">
a <HDF5 dataset "a": shape (100, 1), type "|O">
dn <HDF5 dataset "dn": shape (100, 1), type "|O">
>>> struArray = fs['data']
>>> print(struArray['P'])
<HDF5 dataset "P": shape (100, 1), type "|O">
I don't know how to transfer HDF5 dataset "P" to a numpy array. Any suggestion would be appreciated
arr=struArray['P'][:]do?>>> arr=struArray['P'][:] >>> arr array([[<HDF5 object reference>], [<HDF5 object reference>], [<HDF5 object reference>], [<HDF5 object reference>], [<HDF5 object reference>], [<HDF5 object reference>], ....refsgroup, but I don't know ifh5pycan fetch them for you.scipy.io.loadmatcan handle older style .mat file, but even there the result can have 'opaque' elements. Not everything that matlab saves to a file is translatable into numpy.save( 'statistics_VAD.mat','data', '-v7.3');I get this error usingscipy.io.loadmat:mat_contents = sio.loadmat(mat_fname) raise NotImplementedError('Please use HDF reader for matlab v7.3 files') NotImplementedError: Please use HDF reader for matlab v7.3 files