mat為matlab常用存儲數據的文件格式,python的scipy.io模塊中包含保存和加載mat格式文件的API,使用極其簡單,不再贅述;另附簡易示例如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
# -*- coding: utf-8 -*- import numpy as np import scipy.io as scio # data data = np.array([ 1 , 2 , 3 ]) data2 = np.array([ 4 , 5 , 6 ]) # save mat (data format: dict) scio.savemat( str (F0) + 'Hz.mat' , { 'var_name' :data}) scio.savemat( str (F0) + 'Hz.mat' , { 'var_name' :data, 'var_name2' :data2}) # load mat load_data = scio.loadmat( 'filename' ) |
如上,python黨就可以把保存的mat文件提供給其他matlab專業戶使用。
PS:下面看下python保存加載.mat文件
標簽:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
#coding:utf-8 import scipy.io as sio # save .mat name = 'aaa.mat' x = [[ 1 , 1 , 1 , 2 ], [ 1 , 1 , 1 , 3 ], [ 1 , 1 , 1 , 4 ]] y = [ 5 , 6 , 7 , 8 ] sio.savemat(name, { 'x' : x, 'y' : y}) # load .mat name = 'aaa.mat' data = sio.loadmat(name) x = data[ 'x' ] print ( "x:" , x) y = data[ 'y' ] print ( "y:" , y) |
到此這篇關于Python 保存加載mat格式文件的示例代碼的文章就介紹到這了,更多相關python 保存加載mat文件內容請搜索服務器之家以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持服務器之家!
原文鏈接:https://blog.csdn.net/cshy2013/article/details/107764189