【问题标题】:When Multiplication : IndentationError: expected an indented block当乘法:IndentationError:期望一个缩进块
【发布时间】:2021-02-11 10:10:26
【问题描述】:

当我尝试将两个数字相乘时,在 jupyter 中低于错误。

import tensorflow as tf

tf.executing_eagerly()

x = tf.constant(2)
y = tf.constant(3)
multi = x*y
with tf.Session() as sess:
print(sess.run(multi))

## error 

File "<ipython-input-35-755ab78de6c6>", line 5
    print(sess.run(multi))
    ^
IndentationError: expected an indented block


please help me to solve

【问题讨论】:

  • 不要链接图片,复制问题中的代码并将其格式化为代码
  • @Ben2209 感谢重播,我已经把代码。

标签: python android python-2.7 tensorflow2.0 tensorflow-lite


【解决方案1】:

您必须缩进最后一行(以 print 开头)。

【讨论】:

  • 感谢重播,可以写代码吗? bcz 我不知道缩进。
  • 缩进是python的一个基本概念。你应该学习基础知识。你可以在这里找到适合初学者的资源列表wiki.python.org/moin/BeginnersGuide/Programmers
【解决方案2】:

这是解决方案,特别感谢@Ben2209

tf.__version__

tf.executing_eagerly()

with tf.compat.v1.Session() as sess:
    a = tf.constant(2)
    b = tf.constant(5)
    c = a*b
    print(sess.run(c))

** Output **
10

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-11-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多