TensorFlow MLP不可用类型'列表'

时间:2016-06-22 22:04:24

标签: python list tensorflow

我试图用数组提供MLP。输入数组包含120个浮点数,输出包含2个。

sess.run(init)
# Training cycle
train = True
if train is True:
    for i in range(50):
        for letter in d1:
            #print(letter[0][0][0:5])
            letter[0][0][0:5] = sorted(letter[0][0][0:5], key=itemgetter(0))
            letter[0][0][5:10] = sorted(letter[0][0][5:10], key=itemgetter(0))
            #print(np.squeeze(np.asarray(d1[0])))
            result=[]
            for x in letter[0][0]:
                for y in x:
                    result.append(y)
            div = (result)

            xxx = [letter[0][1][0], int(not letter[0][1][0])]
            xxx = (xxx)
            print(result)

            #print(letter[1])
            _, c = sess.run([optimizer, cost], feed_dict={x: div, y: xxx})

执行最后一行时,它会抛出异常:

Traceback (most recent call last):
  File "tf.py", line 97, in <module>
    _, c = sess.run([optimizer, cost], feed_dict={x: div, y: xxx})
TypeError: unhashable type: 'list'

1 个答案:

答案 0 :(得分:0)

我想您在代码的开头有两个占位符xy

x = tf.placeholder(tf.float32)
y = tf.placeholder(tf.float32)

问题在于,在您的代码中,您再次使用相同名称xy作为两个变量:

for x in letter[0][0]:
    for y in x:
        result.append(y)

这将删除xy的上一个值 相反,您应该使用其他名称,如:

for ix in letter[0][0]:
    for iy in ix:
        result.append(iy)