mat文件是matlab的数据存储的标准格式。
mat文件是标准的二进制文件,还可以ASCII码形式保存和加载,在MATLAB中打开显示类似于单行EXCEL表格。
——from 百度百科
使用scipy包
比如我们路径上有一个tensor.mat的文件(来自数据集Urban Traffic Speed Dataset of Guangzhou, China | Zenodo)
from scipy.io import loadmat
a=loadmat('tensor.mat')
a
'''
{'__header__': b'MATLAB 5.0 MAT-file, Platform: PCWIN64, Created on: Wed Mar 08 20:19:02 2017',
'__version__': '1.0',
'__globals__': [],
'tensor': array([[[40.893, 41.938, 44.098, ..., 42.349, 43.062, 43.246],
[41.227, 45.891, 42.333, ..., 42.15 , 39.34 , 40.87 ],
[42.68 , 41.52 , 42.068, ..., 41.977, 43.372, 41.841],
...,
[42.993, 41.824, 40.173, ..., 42.92 , 40.504, 42.006],
[41.685, 41.996, 40.779, ..., 39.97 , 40.647, 36.771],
[39.543, 41.001, 40.341, ..., 39.242, 39.726, 39.089]],
...,
[[51.88 , 50.378, 52.041, ..., 50.619, 48.85 , 51.191],
[52.075, 54.167, 50.814, ..., 48.619, 43.985, 46.663],
[51.066, 48.728, 49.656, ..., 52.113, 50.615, 53.061],
...,
[50.057, 50.279, 49.887, ..., 51.979, 51.141, 51.116],
[51.418, 52.297, 51.818, ..., 48.772, 51.622, 51.566],
[51.226, 49.731, 51.082, ..., 51.266, 51.352, 52.402]]])}
'''
可以看到输出来的是一个字典类型的文件