简体   繁体   English

在 tensorflow 中创建一个张量数组?

[英]Creating an array of tensors in tensorflow?

Suppose I have two tensor variables each of size 2x4:假设我有两个大小为 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.相反,我想将它们存储在一个名为v的数组中,该数组的大小为 2x2x4。 How do I do this in Tensorflow?我如何在 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 ?我如何初始化v I tried initializing v as a numpy array which did not work.我尝试将v初始化为一个无效的 numpy 数组。 I also tried initializing it as a tensorflow variable, ie.我还尝试将其初始化为 tensorflow 变量,即。 tf.Variable(tf.zeros([2])) but that does not work either. tf.Variable(tf.zeros([2]))但这也不起作用。

Note, a and b are dynamic inputs, ie.注意, ab是动态输入,即。 they are tf.placeholder variables.它们是tf.placeholder变量。

tf.pack() 可能就是你要找的。

作为一个潜在的相关更新,在 TensorFlow 1.0 中tf.pack()被重命名为tf.stack()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM