python 保存 .mat 文件的大小是有限制的,似乎是 5G 以内,如果需要保存几十个 G 的数据的话,可以选用其他方式,比如 h5 文件
import h5py
def h5_data_write(train_data, train_label, test_data, test_label, shuffled_flag):
print("h5py文件正在写入磁盘...")
save_path = "../save_test/" + "train_test_split_data_label_" + shuffled_flag + ".h5"
with h5py.File(save_path, 'w') as f:
f.create_dataset('train_data', data=train_data)
f.create_dataset('train_label', data=train_label)
f.create_dataset('test_data', data=test_data)
f.create_dataset('test_label', data=test_label)
print("h5py文件保存成功!")
def h5_data_read(filename):
""" keys() : 获取本文件夹下所有的文件及文件夹的名字 f['key_name'] : 获取对应的对象 """
file = h5py.File(filename,'r')
train_data = file['train_data'][:]
train_label = file['train_label'][:]
test_data = file['test_data'][:]
test_label = file['test_label'][:]
return train_data, train_label, test_data, test_label