簡體   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