mat數據格式是Matlab的數據存儲的標准格式
在python中可以使用scipy.io中的函數loadmat()讀取mat文件。
import scipy.io as scio path = 'ex3data1.mat' data = scio.loadmat(path)
type(data)
dict #data是字典格式
data.keys() #查看字典的鍵
dict_keys(['__header__', '__version__', '__globals__', 'X', 'y'])
X1 = data['X'] #選擇需要的數據;數組格式
array([[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
...,
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.]])