Home >Backend Development >Python Tutorial >Detailed explanation of the solution to the problem that .mat files cannot be read correctly in python
When importing local .mat data files in python, the correct data cannot always be obtained.
The problem code is as follows:
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)
The output result of the above code is (1,1), and the corresponding data should be (60000,784). At this time, if you directly output data, a corresponding line of code should also be added.
''' [[ {'__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., 0., 0.], [ 0., 0., 0., ..., 0., 0., 0.]], dtype=float32), '__globals__': []}]] '''
The above is the detailed content of Detailed explanation of the solution to the problem that .mat files cannot be read correctly in python. For more information, please follow other related articles on the PHP Chinese website!