我有一個tensor Awith shape[7, 7, 2, 4]和一個tensor Bwith shape [7, 7]。
Tensor B是 的argmax,tensor A其值為0,1。
我想獲得tensor C形狀[7, 7, 4]或[7, 7, 1, 4]來自A和B。
規則是 的(i, j)元素tensor B是 的第二維的索引tensor A。
我怎樣才能快速做到這一點?我試圖通過 CA[B]但它不起作用。誰能幫我?謝謝你。
uj5u.com熱心網友回復:
好的,我用tf.gather_nd來解決這個問題:
tensor_C = tf.gather_nd(tensor_A, tf.expand_dims(tf.argmax(tensor_B, 2), 2), batch_dims=3)
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/522948.html
標籤:Python张量流
