不可用的类型:' list'在打印Tensorflow矢量

时间:2017-12-06 09:21:15

标签: python python-3.x tensorflow

我正在打印Tensorflow的矢量和矩阵。它打印scalar但显示vectorMatrixTensor

的错误

代码如下:

import tensorflow as tf    
scalar = tf.constant([2])
vector = tf.constant([3,4,5])
Matrix = tf.constant([1,2,3],[4,5,6],[7,8,9])
Tensor = tf.constant([ [[1,2,3],[4,5,6],[7,8,9]],
                       [[1,2,3],[4,5,6],[7,8,9]],
                       [[1,2,3],[4,5,6],[7,8,9]] ])
with tf.Session() as session:
    result = session.run(scalar)
    print (result)
    result = session.run(vector)
    print (result)
    result = session.run(Matrix)
    print (result)
    result = session.run(Tensor)
    print (result)

我收到以下错误:

TypeError: unhashable type: 'list'

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

您的第4个陈述出错: 使用

Matrix = tf.constant([ [1,2,3],[4,5,6],[7,8,9] ])
#                    ^ extra parenthesis here

而不是

Matrix = tf.constant([1,2,3],[4,5,6],[7,8,9])