1

Suppose I have two tensor variables each of size 2x4:

v1 = tf.logical_and(a1, b1)
v2 = tf.logical_and(a2, b2)

Instead, I want to store these in an array called v which is of size 2x2x4. How do I do this in Tensorflow? The idea would be something like this:

for i in range(2):
  v[i] = tf.logical_and(a[i],b[i])

How do I initialize v? I tried initializing v as a numpy array which did not work. I also tried initializing it as a tensorflow variable, ie. tf.Variable(tf.zeros([2])) but that does not work either.

Note, a and b are dynamic inputs, ie. they are tf.placeholder variables.

2 Answers 2

2

tf.pack() is probably what you are looking for.

Sign up to request clarification or add additional context in comments.

2 Comments

How would I store each tensor v[i] because I want to run it through a for loop and there might be more than 2 tensors.
put the v[i]s in a normal list, pass the list as the first arg to tf.pack(myListOfTensors)
0

As a potentially relevant update, in TensorFlow 1.0 tf.pack() was renamed to tf.stack().

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.