tensorflow:如何创建与占位符相同形状的const张量

Yan*_*hao 3 python tensorflow tensor

我有一个占位符供输入:

Y = tf.placeholder(dtype=tf.float32, shape=(None, n_outputs))
Run Code Online (Sandbox Code Playgroud)

现在,我想创建一个与Y形状相同的常量:

w = Y.get_shape()
zero = tf.constant(np.zeros(w), dtype=tf.float32)
Run Code Online (Sandbox Code Playgroud)

错误返回:

__index__ returned non-int (type NoneType)
Run Code Online (Sandbox Code Playgroud)

Yan*_*hao 9

在另一张张量可变的张量流中找到答案

zero = tf.fill(tf.shape(Y), 0.0)
Run Code Online (Sandbox Code Playgroud)