Detailed explanation of the solution to the problem that .mat files cannot be read correctly in python

高洛峰
Release: 2017-03-09 09:20:08
Original
2860 people have browsed it

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)
Copy after login

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__': []}]]
'''
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!