教程集 www.jiaochengji.com
教程集 >  Python编程  >  Python入门  >  正文 python mat是什么文件

python mat是什么文件

发布时间:2021-03-25   编辑:jiaochengji.com
教程集为您提供python mat是什么文件等资源,欢迎您收藏本站,我们将为您提供最新的python mat是什么文件资源

.mat就是matlab的文件格式,一般用于matlab和python间的数据传输,python中numpy和scipy提供了一些函数,可以很好的对.mat文件的数据进行读写和处理。 

在python中可以使用scipy.io中的函数loadmat()读取mat文件,函数savemat保存文件。

1、读取文件

如上例:

#coding:UTF-8
import scipy.io as scio
dataFile = 'E://data.mat'
data = scio.loadmat(dataFile)

注意,读取出来的data是字典格式,可以通过函数type(data)查看。

print type(data)

结果显示:

<type 'dict'>

找到mat文件中的矩阵:

print data['A']

结果显示:

[[ 0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
。。。。。。。。。。。
0. 0. 0. 0. 0. 0. 0.
0.36470588 0.90196078 0.99215686 0.99607843 0.99215686 0.99215686
0.78431373 0.0627451 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0.
。。。。。。。。。。。。
0.94117647 0.22745098 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.30196078
。。。。。。。
0. 0. 0. 0. 0. 0. 0.
0. 0. 0. 0. 0. 0. 0. ]]

格式为:

<type 'numpy.ndarray'>

即为numpy中的矩阵格式。

python学习网,大量的免费python视频教程,欢迎在线学习!

您可能感兴趣的文章:
python怎么查看mat格式的文件
python mat是什么文件
Python怎么计算矩阵的和积
python怎样读mat文件格式
Python如何计算两行数据内积
jQuery 版本的文本输入框检查器Input Check
GO语言函数与封装(package,function) 学习总结教程
python setup.py install是什么意思
python中什么叫做脚本
为什么python没有idle

[关闭]
~ ~