繁体   English   中英

字典错误 - Jupyter Notebook - Python 3

[英]Dictionary Error - Jupyter Notebook - Python 3

这个 function 之前工作正常,现在我看不出它出了什么问题。 下面是 function、错误和 hypJson 字典的顺序。 即使我注释掉这个特定部分,我在执行相同任务的其他部分中也会遇到相同的错误。 任何帮助将不胜感激。 谢谢!

 for idx, row in dfT1.iterrows(): hypJson = json.loads(row['hyperparameters']) if hypJson['dropout'] not in d1: d1[hypJson['dropout']] = (row['test_accuracy'] * len(row['test_labels'], len(row['test_labels'])) t1count[hypJson['dropout']] = 1 else: d1[hypJson['dropout']] = (d1[hypJson['dropout']][0] + row['test_accuracy'] * len(row['test_labels']), #correct d1[hypJson['dropout']][1] + len(row['test_labels'])) #total t1count[hypJson['dropout']] = t1count[hypJson['dropout']] + 1

 File "<ipython-input-19-1326a1a48cb8>", line 11 t1count[hypJson['dropout']] = 1 ^ SyntaxError: invalid syntax

 {'dropout': 0, 'optimizer': 'sgd-001-0.9-nesterov', 'deep-dense-top': False, 'convnet-freeze-percent': 0} {'dropout': 0, 'optimizer': 'sgd-001-0.9', 'deep-dense-top': False, 'convnet-freeze-percent': 0} {'dropout': 0, 'optimizer': 'adam', 'deep-dense-top': False, 'convnet-freeze-percent': 0} {'dropout': 0.1, 'optimizer': 'sgd-001-0.9-nesterov', 'deep-dense-top': False, 'convnet-freeze-percent': 0} {'dropout': 0.1, 'optimizer': 'sgd-001-0.9', 'deep-dense-top': False, 'convnet-freeze-percent': 0} {'dropout': 0.1, 'optimizer': 'adam', 'deep-dense-top': False, 'convnet-freeze-percent': 0}

上面的行有不平衡的括号:

d1[hypJson['dropout']] = (row['test_accuracy'] * len(row['test_labels'], len(row['test_labels']))
                                                                    ^^^^ here

应该是:

d1[hypJson['dropout']] = (row['test_accuracy'] * len(row['test_labels']), len(row['test_labels']))

Python 经常会在出现语法错误的那一行之后报告语法错误,因为缺少右括号本身并不是语法错误,因此它会一直扫描代码,直到找到绝对是语法错误的内容,例如(...) t1count在你的情况下:

... = (row['test_accuracy'] * len(row['test_labels'], len(row['test_labels']))
t1count[hypJson['dropout']] = 1
^^^^^^^^ this is seen as (stuff)t1count, which is a syntax error

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM