【问题标题】:Syntax error - unexpected EOF while parsing语法错误 - 解析时出现意外 EOF
【发布时间】:2019-08-26 14:09:07
【问题描述】:

解析时出现意外的 EOF。我想不通。

outputs = []
for i in range (batch_size):

batch_state = np.zeros([1, hidden_layer], dtype=np.float32)
batch_output = np.zeros([1, hidden_layer], dtype=np.float32)

for ii in range (window_size):

    batch_state, batch_output = LSTM_cell(tf.reshape(inputs[i] 
        [ii], (-1, 1)), batch_state, batch_output)

  outputs.append(tf.matmul(batch_output, weights_output + bias_output_layer)          

【问题讨论】:

  • 确保意图正确。我认为第一个for 不应该缩进。
  • 错误是因为括号不匹配。
  • 任何体面的 IDE 都应该可以帮助您避免此类问题。
  • 谢谢@Barmar,你是对的。

标签: python neural-network lstm


【解决方案1】:

如果您修复缩进(仅在 for: 之后而不是之前缩进,始终使用相同的缩进(4 个空格)),请删除第 10/11 行中的换行符并在最后一行添加另一个右括号,代码运行时没有解析或语法错误:

outputs = []
for i in range (batch_size):

    batch_state = np.zeros([1, hidden_layer], dtype=np.float32)
    batch_output = np.zeros([1, hidden_layer], dtype=np.float32)

    for ii in range (window_size):

        batch_state, batch_output = LSTM_cell(tf.reshape(inputs[i][ii], (-1, 1)), batch_state, batch_output)
        outputs.append(tf.matmul(batch_output, weights_output + bias_output_layer))

当然它仍然不起作用,因为它使用了未在截取的代码中定义的变量。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-01-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-25
    相关资源
    最近更新 更多