I need to save some data from Python and read it later with both Python and Matlab. The obvious choice seems to be scipy.io.savemat. But look what happens:
>>> a = {'foo': 0, 'bar': [1,2,3,4,5], 'baz': {'key1': range(10), 'key2': 'Oh No
Mr Bill!'}}
>>> scipy.io.savemat('a.mat',a)
>>> b = scipy.io.loadmat('a.mat')
>>> b['foo']
array([[0]])
>>> b['bar']
array([[1],
[2],
[3],
[4],
[5]])
>>> b['baz']
array([[([u'Oh No Mr Bill!'], [[0], [1], [2], [3], [4], [5], [6], [7], [8], [9]]
)]],
dtype=[('key2', '|O4'), ('key1', '|O4')])
>>> b['baz']['key1']
array([[[[0]
[1]
[2]
[3]
[4]
[5]
[6]
[7]
[8]
[9]]]], dtype=object)
>>> b['baz']['key2']
array([[[u'Oh No Mr Bill!']]], dtype=object)
>>> b['baz']['key2'][0,0]
array([u'Oh No Mr Bill!'],
dtype='<U14')
Everything seems to be stored as 2D arrays for each dictionary... (e.g. foo['baz']['key1'] shows up as a 4D array) Is this a bug or is there a reason for this behavior?