首先导入scipy的包 from scipy.io import loadmat

然后读取 m = loadmat("F:/__identity/activity/论文/data/D001.mat")

注意这里m是一个dict数据结构

>>> m
{'__header__': b'MATLAB 5.0 MAT-file, Platform: PCWIN, Created on: Mon Aug 15 22:16:43 2011', '__globals__': [], 'labels': array([[1],
[3],
[4],
...,
[4],
[3],
[4]], dtype=uint8), 'data': array([[ 1. , 0.35 , 0.265 , ..., 0.0995, 0.0485, 0.07 ],
[ 2. , 0.53 , 0.42 , ..., 0.2565, 0.1415, 0.21 ],
[ 1. , 0.44 , 0.365 , ..., 0.2155, 0.114 , 0.155 ],
...,
[ 1. , 0.59 , 0.44 , ..., 0.439 , 0.2145, 0.2605],
[ 1. , 0.6 , 0.475 , ..., 0.5255, 0.2875, 0.308 ],
[ 2. , 0.625 , 0.485 , ..., 0.531 , 0.261 , 0.296 ]]), '__version__': '1.0'}
>>> m.keys()
dict_keys(['__header__', '__globals__', 'labels', 'data', '__version__'])
>>> m["labels"]
array([[1],
[3],
[4],
...,
[4],
[3],
[4]], dtype=uint8)
>>> m["data"]
array([[ 1. , 0.35 , 0.265 , ..., 0.0995, 0.0485, 0.07 ],
[ 2. , 0.53 , 0.42 , ..., 0.2565, 0.1415, 0.21 ],
[ 1. , 0.44 , 0.365 , ..., 0.2155, 0.114 , 0.155 ],
...,
[ 1. , 0.59 , 0.44 , ..., 0.439 , 0.2145, 0.2605],
[ 1. , 0.6 , 0.475 , ..., 0.5255, 0.2875, 0.308 ],
[ 2. , 0.625 , 0.485 , ..., 0.531 , 0.261 , 0.296 ]])

有点不太懂这个“uint8”

>>> m["labels"][0]
array([1], dtype=uint8)
>>> m["labels"][0][0]
1
>>> m["labels"][0][0] + 1
2
>>> m["labels"][0].as_type("int")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'numpy.ndarray' object has no attribute 'as_type' # 注意时astype不是as_type
>>> m["labels"][0].dtype
dtype('uint8')
>>> m["labels"][0].astype("int")
array([1])

这个数据类型真是醉了:

>>> type(m["labels"][0][0] + 1)
<class 'numpy.int32'>

如果要把它变成dataframe,导入pandas后

>>> df = pd.DataFrame(m["data"])
>>> df.head()
0 1 2 3 4 5 6 7
0 1.0 0.350 0.265 0.090 0.2255 0.0995 0.0485 0.070
1 2.0 0.530 0.420 0.135 0.6770 0.2565 0.1415 0.210
2 1.0 0.440 0.365 0.125 0.5160 0.2155 0.1140 0.155
3 3.0 0.330 0.255 0.080 0.2050 0.0895 0.0395 0.055
4 3.0 0.425 0.300 0.095 0.3515 0.1410 0.0775 0.120

python读取.mat文件的数据的更多相关文章

  1. python读取mat文件

    一.mat文件 mat数据格式是Matlab的数据存储的标准格式.在Matlab中主要使用load()函数导入一个mat文件,使用save()函数保存一个mat文件.对于文件 load('data.m ...

  2. python 读取.mat文件

    导入所需包 from scipy.io import loadmat 读取.mat文件 随便从下面文件里读取一个: m = loadmat('H_BETA.mat') # 读出来的 m 是一个dict ...

  3. python读取.mat文件

    可以先看一下.mat中存了些什么: import scipy.io as sio box_file = '/home/bnrc/formatm/test/1479504458876408533_box ...

  4. python 读取mat文件

    import osimport scipy.io as sio import numpy as np #matlab文件名 matfn='/home/user/devkit/data/meta_det ...

  5. python使用h5py读取mat文件数据,并保存图像

    1 安装h5py sudo apt-get install libhdf5-dev sudo pip install h5py 假设你已经安装好python和numpy模块 2 读取mat文件数据 i ...

  6. python中读取mat文件

    mat数据格式是Matlab的数据存储的标准格式 在python中可以使用scipy.io中的函数loadmat()读取mat文件. import scipy.io as scio path = 'e ...

  7. Python读取SQLite文件数据

    近日在做项目时,意外听说有一种SQLite的数据库,相比自己之前使用的SQL Service甚是轻便,在对数据完整性.并发性要求不高的场景下可以尝试! 1.SQLite简介: SQLite是一个进程内 ...

  8. python操作txt文件中数据教程[3]-python读取文件夹中所有txt文件并将数据转为csv文件

    python操作txt文件中数据教程[3]-python读取文件夹中所有txt文件并将数据转为csv文件 觉得有用的话,欢迎一起讨论相互学习~Follow Me 参考文献 python操作txt文件中 ...

  9. Java读取mat文件

    概述 使用ujmp中的jmatio模块读取.mat文件到java程序中. 其实,ujmp主要是在模块core中实现了矩阵运算,其余模块都是复用了已有的开源库.模块jmatio是复用了已有的JMatIo ...

随机推荐

  1. 仿Windows制作TreeView数据加载

    时间有限就直接贴源码吧,理解思路即可. 页面代码: <asp:TreeView ID="TreeViewLeft" runat="server" Show ...

  2. git database 数据库 平面文件

    w 各个分支  git init 数据库 master分支 git 数据库 “分布式 地位平等的 ”  “git 区别与svn,没有 c/s 主从的概念”“”“c/s” 大家都往这个分支提交,这个分支 ...

  3. Constructor Acquires, Destructor Releases Resource Acquisition Is Initialization

    w https://zh.wikipedia.org/wiki/RAII RAII要求,资源的有效期与持有资源的对象的生命期严格绑定,即由对象的构造函数完成资源的分配(获取),同时由析构函数完成资源的 ...

  4. exe4j中"this executable was created with an evaluation version of exe4j"

    在使用exe4j时,如果您的exe4j没有注册,在运行有exe4j转换的*.jar为*.exe的可执行文件是会提示:"this executable was created with an ...

  5. pc端监听屏幕实现导航固定定位

    要点:占位符 js,监听屏幕滚动事件,当滚动条距离浏览器顶部的距离 大于 要固定定位开始以下元素的距离,则给要固定元素添加fixed样式. 初始化方法时,要给占位符添加样式 function sort ...

  6. 基于websocket搭建简易群聊

    1.前端HTML <!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset=&qu ...

  7. 剑指offer 面试31题

    面试31题: 题目:栈的压入.弹出元素 题:输入两个整数序列,第一个序列表示栈的压入顺序,请判断第二个序列是否为该栈的弹出顺序.假设压入栈的所有数字均不相等.例如序列1,2,3,4,5是某栈的压入顺序 ...

  8. 构建Ruby开发环境(Windows+Eclipse+Aptana Plugin)

    1.安装Ruby ①.从http://rubyinstaller.org/downloads/下载安装包:rubyinstaller-2.2.5-x64.exe,直接安装.(so easy) 2.安装 ...

  9. [MVC学习日记]2014/12/01 初步认识MVC模型。

    2014/12/011.初步认识MVC模型.MVC模式是一种表现模式.它将web应用程序分成三个部分,模型(Model).视图(View).控制器(Controller).Model:是实现业务逻辑层 ...

  10. Struts2笔记01——基础MVC架构(转)

    原始内容:https://www.tutorialspoint.com/struts_2/basic_mvc_architecture.htm Apache Struts 2是用来创建企业级Java ...