python中读取mat文件

Posted tongtong123

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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.]])

 

以上是关于python中读取mat文件的主要内容,如果未能解决你的问题,请参考以下文章