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 calledv 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 initializev? I tried initializingv 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 andb are dynamic inputs, ie. they aretf.placeholder variables.

askedOct 15, 2016 at 23:36
jlcv's user avatar

2 Answers2

2

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

answeredOct 15, 2016 at 23:45
MMN's user avatar
Sign up to request clarification or add additional context in comments.

2 Comments

How would I store each tensorv[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.0tf.pack() was renamed totf.stack().

answeredNov 19, 2017 at 13:16
Matthew Feickert's user avatar

Comments

Your Answer

Sign up orlog in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

By clicking “Post Your Answer”, you agree to ourterms of service and acknowledge you have read ourprivacy 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.