Reputation: 310
I am designing a neural network with Tensorflow. I have a tensor G
with shape: [batch_size, C, 1 + x + y, feature_size]
, I want to calculate the sum of x
and y
vectors inside G
, so that the new G
has shape: [batch_size, C, 3, feature_size]
. So which operation in Tensorflow should I use?
Thank you for your help.
Upvotes: 0
Views: 99
Reputation: 1280
Try the following:
inp = tf.placeholder(tf.float32, shape=(batch_size, C, 1+x+y, feature_size))
s1 = inp[:, :, 0:1, :]
sx = tf.reduce_sum(inp[:, :, 1:x+1, :], axis=2, keepdims=True)
sy = tf.reduce_sum(inp[:, :, -y:, :], axis=2, keepdums=True)
result = tf.concat((s1, sx, sy), axis=2)
Upvotes: 1