For example, I have the tensor
x = tf.constant([[1, 2], [1, 2], [2, 3], [4, 5], [4,5]])
Then I have a list of aggregation indices
idx = [[0,1],[2], [3, 4]]
And apply to the x
and take the mean of each individual tensor
y = []
for i in idx:
y.append(tf.reduce_mean(tf.gather(x, i, 0), 0))
Finally, stack them togather
y = tf.stack(y, 0)
I wanna the results to be
tensor([[1, 2], [2, 3], [4, 5]])
It has problems, the for loop is not efficient, could anyone help me to resolve it?
tensorflow>=1.13
. – giser_yugang May 15 '19 at 1:55