python mat文件读取失败_详解python中无法正确读取.mat文件的解决办法

在Python中尝试使用scipy.io.loadmat读取.mat文件时遇到问题,返回结果不正确。原始代码只显示了文件元信息,而非实际数据。为获取正确数据,需将加载的变量指定为字典中的特定键,如`train_x = x['mnist_train']`和`train_label = label['mnist_train_labels']`。
摘要由CSDN通过智能技术生成

在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.,

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值