Loading hdf5 matlab strings in Python

I'm having trouble reading matlab 7.3 hdf5 file with Python. I am using h5py 2.0.1.

I can read all the matrices that are stored in the file, but I can not read the list of rows. h5py shows strings as a form dataset (1, 894) with type | 04. This dataset contains references to objects that I tried to dereference using syntax h5file[obj_ref].

It gives something like dataset "FFb": shape (4, 1) type "<u2". I interpreted this as an array of characters four in length. This seems to be an ASCII string representation.

Is there an easy way to get strings?

Is there any package providing matlab to support hyth5 python?

+5
source share
2 answers

, , MATLAB? : (|O4 - NumPy). 2- (<u2 - NumPy). h5py , ; 16- .

- , unichr , :

strlist = [u''.join(unichr(c) for c in h5file[obj_ref]) for obj_ref in dataset])

, (for obj_ref in dataset) . (h5file[obj_ref]) . (unichr(c)) Unicode (u''.join()).

, unicode. , ASCII, u'' '' unichr chr.

: h5py; MATLAB NumPy. .

+5

Matlab Group Dataset

dataset.attrs['MATLAB_class']

if Datasetcontains a string, it will return b'char'.

0
source

All Articles