Florin-Catalin Grec Florin-Catalin Grec - 21 days ago 12
Python Question

Access an element in a Multidimensional (3D and 4D) array

I have the following problem: I have a matlab database (.mat) with structure 4x17x4 and 5 fields. The fields inside are "field_a", "field_b", "field_c", "field_d", "field_e". In matlab is quite easy to extract an element from it but I need to find a solution in python. In matlab I do this:

data = {database(:,1,1).a}


How can I extract "data" in python?
What I have done by now is to load matlab database in python:

fnameSISO["States"] = sio.loadmat('databaseSISO_states')


But when I try to extract data it doesn´t work:

data = fnameSISO["States"][:,1,1]


Furthermore I tried to load the database with:

fnameSISO["Loo"] = np.asarray(sio.loadmat('databaseSISO_states'))


It doesn´t work either.

What can I do in this situation? If I save the database in a json file will I be able to extract the elements I need?

Thank you in advance.

Answer

I found the solution. I did a mistake when writing the syntax. Solution:

data = fname["States"]["database"]["field_a"][:,1,1] 
Comments