I need to save a .mat file from python. The mat file should be a cell array of n by 1. The code below does what I need except the output mat file is 1 by n.
JavaScript
x
7
1
import scipy.io as sio
2
import numpy as np
3
4
Label = ['A','Bob','C']
5
mat_file = {'label_mat':np.array(Label, dtype=object)}
6
sio.savemat(r'./test.mat', mat_file)
7
How do I generate the desired n by 1 file?
Advertisement
Answer
Just do a list of lists.
JavaScript
1
7
1
import scipy.io as sio
2
import numpy as np
3
4
Label = [['A'],['Bob'],['C']]
5
mat_file = {'label_mat':np.array(Label, dtype=object)}
6
sio.savemat(r'./test.mat', mat_file)
7