匯入 MATLAB 檔案

Python 資料匯入入門

Hugo Bowne-Anderson

Data Scientist at DataCamp

MATLAB

  • 「Matrix Laboratory」
  • 工程與科學的業界標準
  • 資料儲存為 .mat 檔

ch_2_4.005.png

Python 資料匯入入門

用 SciPy 搞定!

  • scipy.io.loadmat()-讀取 .mat 檔
  • scipy.io.savemat()-寫入 .mat 檔
Python 資料匯入入門

.mat 檔是什麼?

ch_2_4.010.png

Python 資料匯入入門

.mat 檔是什麼?

ch_2_4.011.png

Python 資料匯入入門

匯入 .mat 檔

import scipy.io
filename = 'workspace.mat'
mat = scipy.io.loadmat(filename)

print(type(mat))
<class 'dict'>
  • keys = MATLAB 變數名稱
  • values = 指派給變數的物件
print(type(mat['x']))
<class 'numpy.ndarray'>
Python 資料匯入入門

一起來練習吧!

Python 資料匯入入門

Preparing Video For Download...