python中读取mat文件

 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.]])

猜你喜欢

转载自www.cnblogs.com/tongtong123/p/10641599.html