- 當數據是一個數的時候,可以不管shape進行比較數據的大小,例如,下面的例子b和c的shape不同,但if條件語句的句子會被執行。
with tf.Session() as sess:
a = tf.constant([[[[[[[[[[[[[[[[[[[2]]]]]]]]]]]]]]]]]]],dtype=tf.int32,name='a')
print(a)
b = [[[[a]]]]
c = [[[[[[[[[[[[[[[[[2]]]]]]]]]]]]]]]]]
c = [[[[[c]]]]]
print(sess.run(b))
print(c)
if sess.run(b) == c:
print('execution') # 會執行此句
輸出結果:
Tensor("a_13:0", shape=(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), dtype=int32)
[[[[array([[[[[[[[[[[[[[[[[[[2]]]]]]]]]]]]]]]]]]], dtype=int32)]]]]
[[[[[[[[[[[[[[[[[[[[[[2]]]]]]]]]]]]]]]]]]]]]]
execution