How can I convert complex .mat file to csv using python

前端 未结 1 1754
我在风中等你
我在风中等你 2021-01-23 14:08

I am trying to convert a .mat file to csv using python. The code I am using is

import scipy.io
import numpy as np

data = scipy.io.loadmat(\"wiki.mat\")

for i          


        
1条回答
  •  粉色の甜心
    2021-01-23 14:54

    https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.savetxt.html

    Save an array to a text file.

    You can, unfortunately, only store a single numeric numpy array in a single file. Whereas your .mat file contains a structure:

    >> fieldnames(imdb)
                            ans = 
                            {
                              [1,1] = dob
                              [2,1] = photo_taken
                              [3,1] = full_path
                              [4,1] = gender
                              [5,1] = name
                              [6,1] = face_location
                              [7,1] = face_score
                              [8,1] = second_face_score                          
                              [9,1] = celeb_names
                              [10,1] = celeb_id
                            }
    >> imdb.name(1)        
                            ans = 
                            {
                              [1,1] = Fred Astaire
                            }
    

    It might make sense to convert the data to a numpy dictionary (as described in "Complex matlab-like data structure in python (numpy/scipy)"), and store that as a .csv using How do I convert this list of dictionaries to a csv file? [Python]

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