TensorFlowでscatter_nd関数を使用して、行列の行内の要素の順序を変更しようとしています。例えば、私は、コードを持っているとします行列の行と列内の要素を入れ替える - TensorFlow scatter_nd
indices = tf.constant([[1],[0]])
updates = tf.constant([ [5, 6, 7, 8],
[1, 2, 3, 4] ])
shape = tf.constant([2, 4])
scatter1 = tf.scatter_nd(indices, updates, shape)
$ print(scatter1) = [[1,2,3,4]
[5,6,7,8]]
これはupdates
行列の行を並べ替えます。
行の順序を変更できるだけでなく、各行内の個々の要素の順序を変更したいと考えています。私はベクトル(ランク1のテンソルを)持っている場合、この例では動作します:
indices = tf.constant([[1],[0],[2],[3]])
updates = tf.constant([5, 6, 7, 8])
shape = tf.constant([4])
scatter2 = tf.scatter_nd(indices, updates, shape)
$ print(scatter2) = [6,5,7,8]
私は本当に気に私がscatter2
に行っていたとして、scatter1
の各行内の要素を交換できるようにすることですscatter1
の行ごとに実行します。私はindices
のさまざまな組み合わせを試しましたが、サイズがscatter_nd
関数によってスローされた矛盾したエラーが発生し続けます。