python读取.mat文件的数据
首先导入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文件的数据的更多相关文章
- python读取mat文件
一.mat文件 mat数据格式是Matlab的数据存储的标准格式.在Matlab中主要使用load()函数导入一个mat文件,使用save()函数保存一个mat文件.对于文件 load('data.m ...
- python 读取.mat文件
导入所需包 from scipy.io import loadmat 读取.mat文件 随便从下面文件里读取一个: m = loadmat('H_BETA.mat') # 读出来的 m 是一个dict ...
- python读取.mat文件
可以先看一下.mat中存了些什么: import scipy.io as sio box_file = '/home/bnrc/formatm/test/1479504458876408533_box ...
- python 读取mat文件
import osimport scipy.io as sio import numpy as np #matlab文件名 matfn='/home/user/devkit/data/meta_det ...
- python使用h5py读取mat文件数据,并保存图像
1 安装h5py sudo apt-get install libhdf5-dev sudo pip install h5py 假设你已经安装好python和numpy模块 2 读取mat文件数据 i ...
- python中读取mat文件
mat数据格式是Matlab的数据存储的标准格式 在python中可以使用scipy.io中的函数loadmat()读取mat文件. import scipy.io as scio path = 'e ...
- Python读取SQLite文件数据
近日在做项目时,意外听说有一种SQLite的数据库,相比自己之前使用的SQL Service甚是轻便,在对数据完整性.并发性要求不高的场景下可以尝试! 1.SQLite简介: SQLite是一个进程内 ...
- python操作txt文件中数据教程[3]-python读取文件夹中所有txt文件并将数据转为csv文件
python操作txt文件中数据教程[3]-python读取文件夹中所有txt文件并将数据转为csv文件 觉得有用的话,欢迎一起讨论相互学习~Follow Me 参考文献 python操作txt文件中 ...
- Java读取mat文件
概述 使用ujmp中的jmatio模块读取.mat文件到java程序中. 其实,ujmp主要是在模块core中实现了矩阵运算,其余模块都是复用了已有的开源库.模块jmatio是复用了已有的JMatIo ...
随机推荐
- 《从零开始学Swift》学习笔记(Day 37)——默认构造函数
原创文章,欢迎转载.转载请注明:关东升的博客 结构体和类的实例在构造过程中会调用一种特殊的init方法,称为构造函数.构造函数没有返回值,可以重载.在多个构造函数重载的情况下,运行环境可以根据它的外部 ...
- 写给上C语言课的孩子们
前几天因为五一的关系,参加了好几次同学会,有一些感触和大家分享,到了我们这个年纪,同学们大多家庭.事业小有成就,对自己会有激励,在有的同学显摆自己的车房.电子设备.身家时,忽然想一个人的成熟应该是慢慢 ...
- 巨蟒python全栈开发flask目录
预习1: 1.FlaskWeb框架: https://www.cnblogs.com/DragonFire/category/1246076.html 人工智能技术应用: https://www.cn ...
- UI通过UISlider编写游戏第六感
#import "RootViewController.h" @interface RootViewController (){ UILabel *scoreLabel; } ...
- ehcache 常用配置项详解(三)
EhCache 给我们提供了丰富的配置来配置缓存的设置: 这里列出一些常见的配置项: cache元素的属性: name:缓存名称 maxElementsInMemory:内存中最大缓存对象数 maxE ...
- Jquery的each遍历数据组成JSON
遍历每个标签的值 html代码: <volist name="parArr" id="item" key="$key"> ...
- 老铁,这年头不会点git真不行
作者:武沛齐 出处:http://www.cnblogs.com/wupeiqi/ 版本控制 说到版本控制,脑海里总会浮现大学毕业是写毕业论文的场景,你电脑上的毕业论文一定出现过这番景象! 毕业论文_ ...
- Springboot 错误信息:Required String parameter 'loginname' is not present 引发的研究
@PostMapping("/reg/change")public CommonSdo change( @RequestParam(value = "oldPasswor ...
- JS编写类似弹出窗口样式显示层
JSp中增加div <!-- 提交变更申请 --> <div id="changeWindow" class="easyui-window" ...
- iOS 统计项目代码行数
最近去面试 对面的"他" 问我其中一个问题 是 "你的项目代码量是多少?" 当时的确有点蒙圈, 我可以从整个项目打包的角度考虑项目大小,我还真没想过到底我的项目 ...