首先导入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. 关于Springboot中dubbo整合注意的误区(不对之处请指出)

    这是我的客户端配置! 这是生产的配置, 首先注意一下 scan   我之前尝试这样的客户端配置 然后  果断客户端不能注册接口 @Reference(version="1.0") ...

  2. Ramsey's_theorem Friendship Theorem 友谊定理

    w https://en.wikipedia.org/wiki/Ramsey's_theorem https://zh.wikipedia.org/wiki/拉姆齐定理 在组合数学上,拉姆齐(Rams ...

  3. <2013 08 26> 雅思听力相关

    近两日开始接触雅思题型,初步做了6套剑桥雅思题的听力部分,完成情况还可以,这里做个总结. 1.听力总共约40左右道题目,30min左右完成,结束后有十分钟把答案写到答题卷上.所有听力材料都只播放一遍! ...

  4. window 注册表上下文菜单如何配置?

    注册表结构? Keys Abbreviation Description 描述 HKEY_CLASSES_ROOT HKCR Stores file association and COM objec ...

  5. JS获取短信验证码60秒

    <script language="javascript">    function get_mobile_code(){        $.post("{{ ...

  6. Could not create ServerSocket on address 0.0.0.0/0.0.0.0:9083

    遇到这种情况大家都找不到头绪,是因为你开始运行了hive的metastore,可以输入jps 然后出现如下: 红线所示就是hive metastore的进程 为了重新启动,需要把这个进杀掉: kill ...

  7. ubuntu17.04 配置go环境变量

    把官网下载好的tar解压后,go文件夹放到 /usr/local 目录下 在当前用户的 .bashrc 文件末尾添加 这句话 export PATH=$PATH:/usr/local/go/bin 执 ...

  8. 004-mysql explain详解

    一.使用 使用explain + 查询语句 二.解释说明 1)id列[执行顺序] id列数字越大越先执行,如果说数字一样大,那么就从上往下依次执行,id列为null的就表是这是一个结果集,不需要使用它 ...

  9. Android基础入门教程

    http://www.kancloud.cn/wizardforcel/w3school-android/100491

  10. 《Python数据分析》笔记——数据可视化

    数据可视化 matplotlib绘图入门 为了使用matplotlib来绘制基本图像,需要调用matplotlib.pyplot子库中的plot()函数 import matplotlib.pyplo ...