Skip to content

Instantly share code, notes, and snippets.

@alivcor
Created March 1, 2017 03:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alivcor/921b797a7f0242b9024105f128bc7da8 to your computer and use it in GitHub Desktop.
Save alivcor/921b797a7f0242b9024105f128bc7da8 to your computer and use it in GitHub Desktop.
Appending to a tensor/list in TensorFlow
import tensorflow as tf
#If you're frustrated with tensorflow, and just want to do a simple task of creating a tensor type list and append to it, you're at the right place. The author of this gist was in the same place at the time of writing this gist. And stackoverflow sucks. TF documentation is outdated, help is limited. Have fun !
sess = tf.InteractiveSession()
matrix1 = tf.constant([[1., 2., 3., 4., 5., 6.], [3., 1., 2., 2., 0., 1.]])
matrix2 = tf.constant([[2., 0., 1., 9., 3., 2.5], [1.8, 2.5, 9.4, 1., 0.3, 3.1]])
#lets make a 6x6 matrix by append
A = tf.concat([matrix2], 0) #Now A is a 2 x 6 tensor
A = tf.concat([A, matrix1], 0) #Now A is a 4 x 6 tensor - append matrix1
A = tf.concat([A, matrix1], 0) #Now A is a 6 x 6 tensor - append matrix1
print(A.eval()) #Lets print it
@geraldfj
Copy link

thanks!

@mbe19
Copy link

mbe19 commented Dec 31, 2021

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment