类型错误:预期单个张量时的张量列表 - 将 const 与 tf.random_normal 一起使用时 [英] TypeError: List of Tensors when single Tensor expected - when using const with tf.random_normal
问题描述
我有以下 TensorFlow 代码:
I have the following TensorFlow code:
tf.constant(tf.random_normal([time_step, batch_size], -1, 1))
我收到 TypeError: List of Tensor when single Tensor expected
.你能告诉我代码有什么问题吗?
I am getting TypeError: List of Tensors when single Tensor expected
. Could you tell me what is wrong with the code?
推荐答案
其他人在 另一个帖子 上回答了这个问题.
Someone else has answered this question on another thread.
本质上,tf.constant()
将一个 NumPy 数组作为参数或某种数组或只是一个值.
Essentially, tf.constant()
takes a NumPy array as an argument or some sort of array or just a value.
tf.random_normal()
返回一个张量,它不能作为 tf.constant()
的参数.
tf.random_normal()
returns a Tensor which cannot be an argument to tf.constant()
.
要解决此问题,请使用 tf.Variable()
而不是 tf.constant()
.
To fix this, use tf.Variable()
instead of tf.constant()
.
查看链接中的答案.这个人解释得更好.
See the answer from the link. The person explains it better.
这篇关于类型错误:预期单个张量时的张量列表 - 将 const 与 tf.random_normal 一起使用时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!