怎么在python中使用scipy.io模块处理mat数据

今天就跟大家聊聊有关怎么在python中使用scipy.io模块处理mat数据,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。

python有哪些常用库

python常用的库:1.requesuts;2.scrapy;3.pillow;4.twisted;5.numpy;6.matplotlib;7.pygama;8.ipyhton等。

一、使用模块scipy.io的函数loadmat实现Python对mat数据的读写

1、使用语法

scipy.io.loadmat(file_name, mdict=None, appendmat=True, **kwargs)

2、使用实例

import scipy.io as sio
import numpy as np

#load
data = sio.loadmat('data.mat')

二、使用模块scipy.io的函数savemat实现Python对mat数据的读写

1、使用语法

scipy.io.savemat(file_name, mdict, appendmat=True, format='5', long_field_names=False, 
do_compression=False, oned_as='row')

2、使用实例

import scipy.io as sio
import numpy as np

#save
array_x = np.array([1,2,3,4])
array_y = np.array([5,6,7,8])
sio.savemat('save.mat', {'arrayX': array_x, 'arrayY': array_y})

注意:使用模块scipy.io读取mat数据有时会因为mat文件格式level太高而报错,例如:NotImplementedError: Please use HDF reader for matlab v7.3 files,这时就需要使用h6py方法。

import h6py
mat = h6py.File(mat_path)
mat = np.transpose(mat['you_matrix_name_in_mat'])

看完上述内容,你们对怎么在python中使用scipy.io模块处理mat数据有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注行业资讯频道,感谢大家的支持。