python: read mat file

https://blog.csdn.net/weixin_39223665/article/details/85041775   python reads Matlab's .mat file

https://blog.csdn.net/google19890102/article/details/45672305   python read file-python reads and saves mat file

 

In the actual problem, the .mat file is a cell.

Read with scipy library

Through the scipy.io.loadmat method, the data read out is in dictionary format , which can be viewed through the function 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]

 

Guess you like

Origin blog.csdn.net/weixin_39450145/article/details/113577442