如何创建TensorFlow变量的Python列表

时间:2016-06-06 15:03:28

标签: python list tensorflow

这似乎应该是一件容易的事情,但我在弄清楚其背后的语法时遇到了一些麻烦。基本上,我有这个代码:

Weights = []
Weights.append(tf.Variable(tf.random_normal( n_input, Population[sample][0]), 0, 1))

它返回'int'对象不可迭代的错误。但是,我不能为我的生活弄清楚为什么它甚至试图迭代一个整数。

有什么想法吗?谢谢!

1 个答案:

答案 0 :(得分:2)

您的代码中的问题来自tf.random_normal(shape)。此处shape应该是[n_input, 3]之类的列表。

引发的错误是'int' object is not iterable,因为Python尝试将n_input作为列表读取,并且它是一个int。

您的代码应该是:

weights = []
weights.append(tf.Variable(tf.random_normal([n_input, Population[sample][0], 0., 1.))