假设我们有一个 tensorflow 占位符,如下所示:
x = tf.placeholder(tf.float32, (2, 2, 3 ..., 1))
我想创建另一个张量 y
其形状为 x
除了第一维和第二维之外,它们是 x
的三倍.
y = tf.placeholder(tf.float32, (6, 6, 3, ..., 1))
x
的形状没有预定义,所以我想做的是如下所示:
y = tf.placeholder(tf.float32, (x.shape[0]* 3, x.shape[1] * 3, remaining_are_the_same_as_x_shape))
你能告诉我如何在 tensorflow 中做到这一点吗?
最佳答案
这个怎么样?
x = tf.placeholder(tf.float32, (2, 2, 3 , 1))
shape = x.get_shape().as_list()
shape[0] = shape[0] * 3
shape[1] = shape[1] * 3
y = tf.placeholder(tf.float32, shape=shape)
shape = y.get_shape().as_list()
print(shape)
[6, 6, 3, 1]
关于python - 创建一个占位符,其形状是另一个形状的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52142344/