user1363251
user1363251

Reputation: 421

Manipulation of numpy structured objects

I've read a .mat file with scipy.io:

data = scipy.io.loadmat(etc.)

The function returns a dictionary, and my Matlab structure array is stored in a Numpy structured array. So far, so good. One of my fields is called repet1_F3, and should contain a vector of floats. I've accessed the vector using:

repet1_F3= data['repet1_F3']

repet1_F3 has a weird structure that I can't manipulate:

>>> repet1_F3
array(array([ 0.48856978,  0.74278461, 2.73300925,  2.72642893, 2.73684854,  2.74516561,  2.69143553]), dtype=object)

Am I doing something wrong? How could I convert this object into a standard numpy array?

Upvotes: 2

Views: 65

Answers (1)

hpaulj
hpaulj

Reputation: 231335

loadmat tends to wrap MATLAB structures in numpy object arrays.

array(array([ 0.48856978,  0.74278461, 
 2.73300925,  2.72642893,  2.73684854,  2.74516561,  2.69143553]), dtype=object)

Looks like a 1 element array of dtype object; that element is itself a 1d float array. The outer array probably has shape () (0d).

Try repet1_F3.item() or repet1_F3([]). One of those should give the inner array.

Do you know the MATLAB structure that contains numbers like this?

correction - it should be repet1_F3[()].

Upvotes: 1

Related Questions