Created
March 1, 2017 03:17
-
-
Save alivcor/921b797a7f0242b9024105f128bc7da8 to your computer and use it in GitHub Desktop.
Appending to a tensor/list in TensorFlow
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks!