类型错误:张量清单时,单张量预计 - 使用常量与tf.random_normal
问题描述:
时,我有以下TensorFlow代码:类型错误:张量清单时,单张量预计 - 使用常量与tf.random_normal
tf.constant(tf.random_normal([time_step, batch_size], -1, 1))
我得到TypeError: List of Tensors when single Tensor expected
。你能告诉我代码有什么问题吗?
答
别人已经https://*.com/a/35662013/8071521
本质上回答了另一个线程这个问题,tf.constant()
需要NumPy的数组作为参数或某种数组或只是一个值。
tf.random_normal()
返回一个张量,其中不能是tf.constant()
的参数。
要解决此问题,请使用tf.Variable()
而不是tf.constant()
。
查看链接的答案。这个人更好地解释它。
答
tf.constant
假设有一个不变的参数 - value
。这里的value
可以是一个常数值,或者是类型为dtype
的值列表。您无法创建一个具有另一个张量作为其值的常量张量。