當(dāng)我使用 tf.boolean_mask 時(shí),結(jié)果是扁平化的。tensor7 = tf.constant( [[ 0, 1, 2, 3, -1],[ 2, 3, 4, -1, -1],[ 3, 6, 5, 4, 3]], tf.int64)mask7 = tf.constant([[ True, True, True, True, False], [ True, True, True, False, False], [ True, True, True, True, True]], tf.bool)result7=tf.boolean_mask(tensor7, mask7, axis=0) with tf.Session() as sess: print(sess.run([ result7 ]))數(shù)組([0, 1, 2, 3, 2, 3, 4, 3, 6, 5, 4, 3])]有沒有辦法使用它來保留原始的 3 數(shù)組形狀?各個(gè)陣列的形狀應(yīng)該改變,因?yàn)樗鼈儸F(xiàn)在更短了。我正在尋找這樣的東西[數(shù)組([[ 0, 1, 2, 3 ], [ 2, 3, 4 ], [ 3, 6, 5, 4, 3]])
1 回答

白豬掌柜的
TA貢獻(xiàn)1893條經(jīng)驗(yàn) 獲得超10個(gè)贊
您的期望在邏輯上可能不合理,正如在與您的問題類似的功能請(qǐng)求中進(jìn)一步指出的那樣。您需要為張量提供動(dòng)態(tài)形狀,這在 TensorFlow 中只有有限的支持(例如Ragged Tensors)。
添加回答
舉報(bào)
0/150
提交
取消