首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >字典错误-朱庇特笔记本- Python 3

字典错误-朱庇特笔记本- Python 3
EN

Stack Overflow用户
提问于 2020-06-30 20:25:22
回答 1查看 154关注 0票数 1

这个功能以前运行得很好,现在我看不出它出了什么问题。下面是按这个顺序排列的函数、错误和hypJson字典。即使我注释掉这个特定的部分,在执行相同任务的其他部分也会出现相同的错误。任何帮助都将不胜感激。谢谢!

代码语言:javascript
复制
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

代码语言:javascript
复制
  File "<ipython-input-19-1326a1a48cb8>", line 11
    t1count[hypJson['dropout']] = 1
          ^
SyntaxError: invalid syntax

代码语言:javascript
复制
{'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}

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-06-30 20:34:29

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

代码语言:javascript
复制
d1[hypJson['dropout']] = (row['test_accuracy'] * len(row['test_labels'], len(row['test_labels']))
                                                                    ^^^^ here

它应该是:

代码语言:javascript
复制
d1[hypJson['dropout']] = (row['test_accuracy'] * len(row['test_labels']), len(row['test_labels']))

Python通常会在语法错误后面的行上报告语法错误,因为缺少的结束括号本身并不是语法错误,所以它一直扫描代码,直到找到肯定是语法错误的东西,比如您的示例中的(...) t1count

代码语言:javascript
复制
... = (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
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62665624

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档