0

Im trying to load a .mat file in python using:

Y = scipy.io.loadmat('XYZ.mat')

These are the keys of the dictionary created

dict_keys(['__header__', '__version__', '__globals__', 'X', 'Y'])

type(Y['X']) is

<class 'scipy.io.matlab.mio5_params.MatlabObject'>

Now, i want the contents of key X as a numpy array.

Y = np.array(Y['X'])

does not work. When i print Y, this is what i get:

array([[(array([[[........]]]), array([[  5, 201,  61]], dtype=uint8))]],
  dtype=[('data', 'O'), ('size', 'O')])

How do i access the elements of the array?

5
  • What is the error message you are getting? Commented Feb 12, 2022 at 12:47
  • Did you try Y['X'][0]? Commented Feb 12, 2022 at 14:38
  • Or you could read the documentation: docs.scipy.org/doc/scipy/tutorial/io.html Commented Feb 12, 2022 at 14:42
  • @CrisLuengo, Y['X'][0][0] of the matlab object did the trick! thank you for pointing in the right direction! Commented Feb 12, 2022 at 16:39
  • Recently I explored how a numpy structured array is handled by savemat/loadmat. At the MATLAB end it is imported as struct. In scipy is imported a structured array with object dtype fields.stackoverflow.com/questions/70963723/… Commented Feb 12, 2022 at 16:46

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.