【问题标题】:SyntaxError: invalid character in identifier - Pytorch 1.3.1SyntaxError:标识符中的无效字符 - Pytorch 1.3.1
【发布时间】:2019-12-28 15:59:26
【问题描述】:

执行以下方法时:

def flatten(t):
    t = t.reshape(1, −1)
    t = t.squeeze()
    return t

Python 抱怨第二个参数。

  File "pytorch.py", line 16
t = t.reshape(1, −1)
                  ^       SyntaxError: invalid character in identifier

我的 pytorch 版本是 1.3.1。 我已经尝试删除参数之前的空格,但没有效果。有什么想法吗?

【问题讨论】:

  • 按照现在的样子,你的方法好像没有缩进?
  • reddit 在粘贴后搞砸了。感谢您的提示!

标签: character pytorch reshape identifier


【解决方案1】:

-1 中的字符不是连字符。相反,它是来自 unicode 的实际减号。 这使得 python 解释器认为 -1 是标识符而不是 -1 值。

您可能从具有这种程式化字符的地方复制了代码。只需将 替换为-

【讨论】:

  • 就是这样。非常感谢。
猜你喜欢
  • 1970-01-01
  • 2018-10-03
  • 2023-03-09
  • 2013-01-28
  • 2017-06-10
  • 1970-01-01
  • 1970-01-01
  • 2019-11-25
  • 2021-11-29
相关资源
最近更新 更多