繁体   English   中英

乘法时:IndentationError:期望缩进块

[英]When Multiplication : IndentationError: expected an indented block

当我尝试将两个数字相乘时,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


请帮我解决

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

这是解决方案,特别感谢@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

暂无
暂无

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

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