當我使用 tf.boolean_mask 時,結果是扁平化的。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 ]))數組([0, 1, 2, 3, 2, 3, 4, 3, 6, 5, 4, 3])]有沒有辦法使用它來保留原始的 3 數組形狀?各個陣列的形狀應該改變,因為它們現在更短了。我正在尋找這樣的東西[數組([[ 0, 1, 2, 3 ], [ 2, 3, 4 ], [ 3, 6, 5, 4, 3]])
1 回答

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