Saving Numpy Structure Array to *.mat file

前端 未结 1 1440
旧巷少年郎
旧巷少年郎 2020-12-19 07:30

I am using numpy.loadtext to generate a structured Numpy array from a CSV data file that I would like to save to a MAT file for colleagues who are more familiar

相关标签:
1条回答
  • 2020-12-19 08:04

    You can do scipy.io.savemat('test.mat', {'mydata': mydata}).

    This creates a struct mydata with fields foo and bar in the file.

    Alternatively, you can pack your loop in a dict comprehension:

    tmp = {varname: mydata[varname] for varname in mydata.dtype.names}
    

    I don't think creating a temprorary dictionary duplicates data in memory, because Python generally only stores references, and numpy in particular tries to create views into the original data whenever possible.

    0 讨论(0)
提交回复
热议问题