簡體   English   中英

如何將多個.mat 文件加載到 python 腳本中

[英]How to load multiple .mat files into a python script

我想將 38.mat 文件加載到字典中以保存它們。 the.mat 文件被命名為 subject1 到 subject38 我嘗試的代碼是一個簡單的 for 循環

    import scipy.io as sio
    data = {}
    for i in range(1, 38):
        data["data{}".format(i)] = sio.loadmat('subject{}.mat'.format(i))

我得到的錯誤是:

Traceback(最近一次調用最后一次):文件“D:/senior project/python/dataAqu.py”,第 7 行,在 data["data{0}".format(i)] = sio.loadmat('subject{0 }.mat'.format(i)) 文件“C:\Users\mamdo\AppData\Roaming\Python\Python27\site-packages\scipy\io\matlab\mio.py”,第 208 行,在 loadmat matfile_dict = MR .get_variables(variable_names) 文件“C:\Users\mamdo\AppData\Roaming\Python\Python27\site-packages\scipy\io\matlab\mio5.py”,第 292 行,在 get_variables res = self.read_var_array(hdr,進程)文件“C:\Users\mamdo\AppData\Roaming\Python\Python27\site-packages\scipy\io\matlab\mio5.py”,第 252 行,在 read_var_array 返回 self._matrix_reader.array_from_header(header, process) File "mio5_utils.pyx", line 675, in scipy.io.matlab.mio5_utils.VarReader5.array_from_header File "mio5_utils.pyx", line 705, in scipy.io.matlab.mio5_utils.VarRe ader5.array_from_header File "mio5_utils.pyx", line 778, in scipy.io.matlab.mio5_utils.VarReader5.read_real_complex File "mio5_utils.pyx", line 450, in scipy.io.matlab.mio5_utils.VarReader5.read_numeric File "mio5_utils .pyx", line 355, in scipy.io.matlab.mio5_utils.VarReader5.read_element File "streams.pyx", line 194, in scipy.io.matlab.streams.ZlibInputStream.read_string File "pyalloc.pxd", line 9 , 在 scipy.io.matlab.pyalloc.pyalloc_v MemoryError

所以我發現了問題。 mat文件不應該被任何其他程序打開——比如matlab——如果出現錯誤重新啟動計算機。

此外,如果存在 memory 問題,請嘗試單獨集成 mat 文件並執行您需要的任何代碼,然后加載下一個文件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM