我得到一個TensofFlow張量的形狀為:(?,)這個答案說的?意思是維在圖中不是固定的,并且在運行調(diào)用之間可以變化。?與尾隨的逗號結(jié)合是什么意思?文檔章節(jié)和詩句將不勝感激。我發(fā)現(xiàn)語法非常難以使用Google。
2 回答

慕的地10843
TA貢獻1785條經(jīng)驗 獲得超8個贊
逗號表示維度表示為1-elem 元組而不是 int。
每個張量在創(chuàng)建時默認為n維:
import tensorflow as tf
t = tf.constant([1, 1, 1])
s = tf.constant([[1, 1, 1],[2,2,2]])
print("0) ", tf.shape(t))
print("1) ", tf.shape(s))
0) Tensor("Shape_28:0", shape=(1,), dtype=int32)
1) Tensor("Shape_29:0", shape=(2,), dtype=int32)
但是,您可以重塑形狀以得到更“完整”的形狀(即n X m / n X m X r ...暗):
print("2) ", tf.reshape(t, [3,1]))
print("3) ", tf.reshape(s, [2,3]))
2) Tensor("Reshape_12:0", shape=(3, 1), dtype=int32)
3) Tensor("Reshape_13:0", shape=(2, 3), dtype=int32)
添加回答
舉報
0/150
提交
取消