成人国产在线小视频_日韩寡妇人妻调教在线播放_色成人www永久在线观看_2018国产精品久久_亚洲欧美高清在线30p_亚洲少妇综合一区_黄色在线播放国产_亚洲另类技巧小说校园_国产主播xx日韩_a级毛片在线免费

資訊專欄INFORMATION COLUMN

python中無法正確讀取.mat文件的解決辦法

eechen / 3025人閱讀

摘要:在中導(dǎo)入本地數(shù)據(jù)文件時,總是無法得到正確的數(shù)據(jù)。此時,如果直接輸出,會看到以下結(jié)果可見,如果本地文件包含了額外的信息,則單純使用無法直接讀取到所需數(shù)據(jù),還應(yīng)該補(bǔ)充一行對應(yīng)的代碼。

在python中導(dǎo)入本地.mat數(shù)據(jù)文件時,總是無法得到正確的數(shù)據(jù)。

問題代碼如下:

from numpy import *
import scipy.io

mnist_train = "D:Machine LearningTensorFlowSoftmax Regressionmnist_datasetmnist_train.mat"
mnist_train_labels = "D:Machine LearningTensorFlowSoftmax Regressionmnist_datasetmnist_train_labels.mat"

x = scipy.io.loadmat(mnist_train)
label = scipy.io.loadmat(mnist_train_labels)

print(x.shape)
上段代碼輸出的結(jié)果是(1,1),而對應(yīng)的數(shù)據(jù)應(yīng)是(60000,784)。此時,如果直接輸出x,會看到以下結(jié)果:
"""
[[ {"__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__": []}]]
"""
可見,如果本地mat文件包含了額外的信息,則單純使用scipy.io.loadmat()無法直接讀取到所需數(shù)據(jù),還應(yīng)該補(bǔ)充一行對應(yīng)的代碼。
x = scipy.io.loadmat(mnist_train)
train_x = x["mnist_train"]
label = scipy.io.loadmat(mnist_train_labels)
train_label = label["mnist_train_labels"]

文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請注明本文地址:http://systransis.cn/yun/38508.html

相關(guān)文章

  • pythonmat矩陣和matlabnpy矩陣實現(xiàn)互相轉(zhuǎn)換

      小編寫這篇文章的目的,主要是給大家介紹關(guān)于python和npy矩陣的相關(guān)介紹,下面會給大家做出一個詳細(xì)的解答,希望可以給各位讀者帶來幫助。  mat矩陣和npy矩陣互相轉(zhuǎn)換  numpy.narray矩陣保存為mat文件  importnumpyasnp   importscipy.ioasio   mat_path='your_mat_save_path'   mat=np....

    89542767 評論0 收藏0

發(fā)表評論

0條評論

最新活動
閱讀需要支付1元查看
<