Python - AttributeError: #39;dict#39; object has no attribute #39;train#39;(Python-AttributeError:#39;dict39;对象没有属性#39;序列#39;)
本文介绍了Python-AttributeError:';dict&39;对象没有属性';序列';的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个错误:AttributeError:‘dict’对象在下面的代码中没有‘Train’属性:
def main(unused_argv):
# Load training and eval data
image_ind = 10
svhn = sio.loadmat('train_32x32.mat')
# access to the dict
x_train = svhn['X']
y_train = svhn['y']
# show sample
plt.imshow(x_train[:,:,:,image_ind])
print(y_train[image_ind])
train_data = svhn.train.images # Returns np.array
train_labels = np.asarray(svhn.train.labels, dtype=np.int32)
eval_data = sio.loadmat('test_32x32.mat')
# access to the dict
x_test = eval_data['X']
y_test = eval_data['y']
eval_dataSVHN = eval_data.test.images # Returns np.array
eval_labels = np.asarray(eval_data.test.labels, dtype=np.int32)
执行时,我收到错误:
train_data = svhn.train.images # Returns np.array
AttributeError: 'dict' object has no attribute 'train'
我如何修复此问题?
推荐答案
我看不出有什么问题...scipy.io.loadmat
returns a dictionary,基本词典没有"系列"属性。如果在matlab文件中有一个"系列"变量,那么它将被存储为字典键,这样您就可以svhn['train']
(而不是svhn.train
)来访问它。
这篇关于Python-AttributeError:';dict&39;对象没有属性';序列';的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:Python-AttributeError:';dict&39;对象没有属性';序列';


基础教程推荐
猜你喜欢
- 如何在Python中绘制多元函数? 2022-01-01
- 哪些 Python 包提供独立的事件系统? 2022-01-01
- Python 的 List 是如何实现的? 2022-01-01
- 使用 Google App Engine (Python) 将文件上传到 Google Cloud Storage 2022-01-01
- 合并具有多索引的两个数据帧 2022-01-01
- 使用Python匹配Stata加权xtil命令的确定方法? 2022-01-01
- 使 Python 脚本在 Windows 上运行而不指定“.py";延期 2022-01-01
- 如何在 Python 中检测文件是否为二进制(非文本)文 2022-01-01
- 症状类型错误:无法确定关系的真值 2022-01-01
- 将 YAML 文件转换为 python dict 2022-01-01