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.
import scipy.io as sio import numpy as np Label = ['A','Bob','C'] mat_file = {'label_mat':np.array(Label, dtype=object)} sio.savemat(r'./test.mat', mat_file)
How do I generate the desired n by 1 file?
Advertisement
Answer
Just do a list of lists.
import scipy.io as sio import numpy as np Label = [['A'],['Bob'],['C']] mat_file = {'label_mat':np.array(Label, dtype=object)} sio.savemat(r'./test.mat', mat_file)