在python中导入本地.mat数据文件时,总是无法得到正确的数据。
问题代码如下:
from numpy import *
import scipy.io
mnist_train = 'D:\Machine Learning\TensorFlow\Softmax Regression\mnist_dataset\mnist_train.mat'
mnist_train_labels = 'D:\Machine Learning\TensorFlow\Softmax Regression\mnist_dataset\mnist_train_labels.mat'
x = scipy.io.loadmat(mnist_train)
label = scipy.io.loadmat(mnist_train_labels)
print(x.shape)
上段代码输出的结果是(1,1),而对应的数据应是(60000,784)。此时,如果直接输出x,会看到以下结果:
'''
[[ {'__version__': '1.0', '__header__': b'MATLAB 5.0 MAT-file, Platform: PCWIN, Created on: Tue Nov 29 12:43:31 2011',
'mnist_train': array([[ 0., 0., 0., ..., 0., 0., 0.],
[ 0., 0., 0., ..., 0., 0., 0.],
[ 0., 0., 0., ..., 0., 0., 0.],
...,
[ 0., 0., 0., ..., 0., 0., 0.],
[ 0., 0., 0., ..., 0.,