Python读取mat格式数据

Python中读取mat格式数据并保存为mat格式文件

提示:适用于机器学习和深度学习之间的跳跃者

例如:某些源码为Python,但自己主要适用MATLAB时


数据读取和保存

例如:Python读取mat格式数据时直接用scipy读取得到的为字典格式数据,如需数组则需要numpy.array转换一下。

import scipy.io as scio
#read data
data = scio.loadmat('example.mat')
X = data['X']
Y = data['Y']
#save data
data_path = '.../result/result.mat'
scio.savement(data_path,{'Acc': accuracy})

代码示例

seedings = []
total_time = []

repeat_times = 2000
repeat_times1 = 1500

for i in range(repeat_times):
    start_time = time.time()
    seeding = kmc2.kmc2(X, 100, chain_length=100, afkmc2=True, random_state=None, weights=None)  # Run k-MC2 with k=100
    end_time = time.time()
    margin = end_time-start_time
    seedings.append(seeding)
    total_time.append(margin)
    scio.savemat('initialization100true2000.mat', {'A':seedings})
    scio.savemat('time100true2000.mat',{'time':total_time})

你可能感兴趣的:(python,numpy,开发语言)