Luresurgam
Luresurgam

Reputation: 13

The matrix obtained by tf.concat () is not the same as before the merge

import tensorflow as tf
import random
sess=tf.Session()
x1=tf.random_normal(shape=[300,5],mean=0,stddev=1,dtype=tf.float32)
x2=tf.random_normal(shape=[300,5],mean=1,stddev=2,dtype=tf.float32)
x3=tf.random_normal(shape=[300,5],mean=5,stddev=3,dtype=tf.float32)
X=tf.placeholder("float32",[None,5])
X=tf.concat([x1,x2,x3],0)
print(sess.run(x3));print(sess.run(x1));print(sess.run(x2));print(sess.run(tf.shape(x1)))
print(sess.run(X));print(sess.run(tf.shape(X)))

Display is

enter image description here

enter image description here

Should not be the beginning of the merged matrix X, the first matrix x1 is the same? Why is X different from x1, X2, X3?

Upvotes: 1

Views: 50

Answers (1)

Avijit Dasgupta
Avijit Dasgupta

Reputation: 2065

I think you are running the graph twice. print(sess.run(x3));print(sess.run(x1));print(sess.run(x2));print(sess.run(tf.shape(x1)))

runs the graph and generates random numbers once.

`print(sess.run(X));print(sess.run(tf.shape(X)))` 

runs the graph second time and generating random numbers.

Try this instead:

X, x1 = sess.run([X, x1])
print(X)
print(x1)

Upvotes: 1

Related Questions