我正在打印Tensorflow的矢量和矩阵。它打印scalar
但显示vector
,Matrix
和Tensor
代码如下:
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'
我该如何解决这个问题?
答案 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])