[SciPy-User] How to handle a scipy.io.loadmat - related bug: parts of the data inaccessible after loadmat

Matthew Brett matthew.brett at gmail.com
Thu Feb 23 20:41:34 EST 2017


Hi,

On Thu, Feb 23, 2017 at 5:12 AM, Propadovic Nenad <npropadovic at gmail.com> wrote:
> Hello Jason, than you a lot for the answer to my post. I was aware of the
> squeeze_me=True option, I think I mentioned it in my initial question post.
>
> However, as I stated in the answer to Gregors kind answer, I actually need a
> way to inspect the parts of the access path in the data structure I import
> form the x.mat-file, and if I use squeeze_me=True, parts like 'RPDO2'
> disappear completely:
>
>
> import scipy.io
>
> y = scipy.io.loadmat("x.mat", squeeze_me=True)
> cd = y['CanData']
> msg = cd['msg']
> print msg
>
> Output:
> ((array(((array([ 61.96,  61.96,  61.96]), u'PosAct'), (array([-0.05, -0.1 ,
> 0.3 ]), u'VelAct')),
>       dtype=[('PosAct', 'O'), ('VelAct', 'O')]), array([ 0.      ,
> 0.003968,  0.007978])),)
>
> And I really need to be able to find it by some kind of inspection, so that
> I don't return parts of the structure that don't correspond to the intention
> of the person searching.

Sorry if I'm not following, but, does this help?

In [36]: y = scipy.io.loadmat("x.mat")

In [37]: y['CanData'][0, 0]['msg'][0, 0]['RPDO2']
Out[37]:
array([[ (array([[ 0.      ,  0.003968,  0.007978]]), array([[
(array([[(array([[ 61.96,  61.96,  61.96]]), array(['PosAct'],
      dtype='<U6'))]],
      dtype=[('Values', 'O'), ('Name', 'O')]), array([[(array([[-0.05,
-0.1 ,  0.3 ]]), array(['VelAct'],
      dtype='<U6'))]],
      dtype=[('Values', 'O'), ('Name', 'O')]))]],
      dtype=[('PosAct', 'O'), ('VelAct', 'O')]))]],
      dtype=[('timest', 'O'), ('sig', 'O')])

In [54]: y2 = scipy.io.loadmat('x.mat', squeeze_me=True, struct_as_record=False)

In [55]: y2['CanData'].msg.RPDO2
Out[55]: <scipy.io.matlab.mio5_params.mat_struct at 0x10fda7b00>

Best,

Matthew


More information about the SciPy-User mailing list