码迷,mamicode.com
首页 > 编程语言 > 详细

Python读取mat文件

时间:2020-04-12 07:54:51      阅读:76      评论:0      收藏:0      [点我收藏+]

标签:scipy   多个   数据类型   参考   htm   html   path   blog   处理   

  参考资料:

  https://www.cnblogs.com/anyview/p/5064174.html

  在处理数据的时候可能会遇到原始数据储存在.mat文件的情况,mat文件当然就是matlab中保存的工作区文件啦,里面可能会有一个或者多个矩阵。给你一个mat文件你又想用python处理,该怎么办呢?

  在网上找到了一个简单的解决方案,下面连带效果图一起贴出来:

import scipy.io as scio

train_imgs_path = ‘train_imgs.mat‘
train_imgs = scio.loadmat(train_imgs_path)
print(train_imgs)
{‘__header__‘: b‘MATLAB 5.0 MAT-file Platform: nt, Created on: Fri Apr  3 17:38:47 2020‘, ‘__version__‘: ‘1.0‘, 
‘__globals__‘: [], 
‘train_imgs‘: 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]], dtype=int32)
}

  显然返回的是一个字典对象,在其中取出我们需要的数组即可。不过我很诧异的是这个数组的数据类型居然是ndarray,不管那么多了,好用就行。

Python读取mat文件

标签:scipy   多个   数据类型   参考   htm   html   path   blog   处理   

原文地址:https://www.cnblogs.com/chester-cs/p/12683491.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!