如何使用tensorflow正确交换数组中的两个值?

如何使用tensorflow正确交换数组中的两个值?,tensorflow,Tensorflow,给定两个索引,在张量中交换两个值的最佳方法是什么 下面是我到目前为止使用变量所做的工作 import numpy as np import tensorflow as tf indices = tf.constant([0,1]) data = tf.Variable([1,2,8]) data = tf.scatter_update(data,indices,tf.gather(data,tf.reverse(indices,[0]))) init_op = tf.initialize_al

给定两个索引,在张量中交换两个值的最佳方法是什么

下面是我到目前为止使用变量所做的工作

import numpy as np
import tensorflow as tf

indices = tf.constant([0,1])
data = tf.Variable([1,2,8])
data = tf.scatter_update(data,indices,tf.gather(data,tf.reverse(indices,[0])))
init_op = tf.initialize_all_variables()

sess = tf.Session()
sess.run([init_op])
print "data:", sess.run(data)
它给了我

答:[2 1 8]

我敢肯定这很难看,还有别的办法吗

问候,