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 ...
随机推荐
- mysql 日期加减天数
MySQL 为日期增加一个时间间隔:date_add() now() //now函数为获取当前时间 select date_add(now(), interval 1 day); - 加1 ...
- delphi 创建服务,安装与卸载服务
运行Delphi7,选择菜单File-->New-->Other--->Service Application.将生成个服务框架.将工程保存为ServiceDemo.dpr和Unit ...
- SpringBoot整合Dubbo报错: java.lang.ClassCastException
com.alibaba.dubbo.rpc.RpcException: Failed to invoke remote proxy method queryGoodsLimitPage to regi ...
- 在VM虚拟机中安装Centos7操作系统(三)
首先我们要下载 Centos https://www.centos.org/ 这个是Centos官方 最新版本 7 https://www.centos.org/download/ 提供有 DVD安 ...
- Delphi重定义的消息结构
// 除去DDE和MDI消息,一共159个消息,其中部分消息仅仅的转定义 // 普通消息,有两个参数和结果 PMessage = ^TMessage; TMessage = packed record ...
- ES6学习笔记(一)——let和const
1.ES6学习之let.const (1).var.let.const 变(常)量声明 ES5 只有全局作用域和函数作用域,没有块级作用域,这带来很多不合理的场景. 在ES6中let就诞生了,实际上它 ...
- ThinkPHP官网瀑布流实现分享
很多人都想做瀑布流的效果,这里告诉大家官网使用的方法. 首先要下载瀑布流的插件jquery.masonry.min.js 地址:http://masonry.desandro.com/index.ht ...
- Spring Boot之AOP面向切面编程-实战篇
目录 前言 编程范式主要有以下几类 引入pom依赖 aop注解 实现日志分割功能 前言 AOP是一种与语言无关的程序思想.编程范式.项目业务逻辑中,将通用的模块以水平切割的方式进行分离统一处理,常用于 ...
- HDU 1159 Common Subsequence(POJ 1458)
Common Subsequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- PAT 天梯赛 L1-006. 连续因子 【循环】
题目链接 https://www.patest.cn/contests/gplt/L1-006 思路 输出的连续因子 的乘积 也要是这个数的因子 就每个数先找它的单因子 然后每个单因子往上一个一个遍历 ...