Python to MATLAB: exporting list of strings using scipy.io

前端 未结 2 716
情话喂你
情话喂你 2021-01-11 11:47

I am trying to export a list of text strings from Python to MATLAB using scipy.io. I would like to use scipy.io because my desired .mat file should include both numerical ma

2条回答
  •  我在风中等你
    2021-01-11 11:58

    You need to make my_list an array of numpy objects:

    import scipy.io
    import numpy as np
    my_list = np.zeros((3,), dtype=np.object)
    my_list[:] = ['abc', 'def', 'ghi']
    scipy.io.savemat('test.mat', mdict={'my_list': my_list})
    

    Then it will be saved in a cell format. There might be a better way of putting it into a np.object, but I took this way from the Scipy documentation.

提交回复
热议问题