How do I add only certain columns to a tensor in tensorflow?

Solution 1:

The simplest option would be to just use tf.concat:

import tensorflow as tf

test = tf.constant([[[100., 2., -30.],[-4,5,6]], [[4., 5., 6.],[-7,8,9]]]) # matrix
test1 = tf.constant([[[100.]],[[  8.]]])

print(tf.concat([test[:,:,0:2] + test1, test[:,:,2:]], axis=-1))
tf.Tensor(
[[[200. 102. -30.]
  [ 96. 105.   6.]]

 [[ 12.  13.   6.]
  [  1.  16.   9.]]], shape=(2, 2, 3), dtype=float32)