https://blog.csdn.net/weixin_39223665/article/details/85041775 python读取Matlab的.mat文件
https://blog.csdn.net/google19890102/article/details/45672305 python读取文件——python读取和保存mat文件
实际问题中,.mat文件是一个cell.
用scipy库进行读取
通过scipy.io.loadmat方法,读取出来的数据data是字典格式,可以通过函数type(data)查看。
import scipy.io #用于加载mat文件
import numpy as np
labels = scipy.io.loadmat('F:\\imagelabels.mat') #用scipy.io.loadmat读取.mat文件
print("labels:",labels)
#输出:labels: {'__header__': b'MATLAB 5.0 MAT-file, Platform: GLNX86, Created on: Thu Feb 19 15:43:33 2009',
#'__version__': '1.0', '__globals__': [], 'labels': array([[77, 77, 77, ..., 62, 62, 62]], dtype=uint8)}
data_labels=labels.get('labels') #取出字典里的labels
print("data_labels:",data_labels)
#输出:data_labels: [[77 77 77 ... 62 62 62]]
labels = labels['labels'][0] #取出字典里的labels id
print("labels:",labels)
#输出:labels: [77 77 77 ... 62 62 62]