TypeError:无法散列的类型:'numpy.ndarray'-张量流-numpy

时间:2020-09-17 11:57:11

标签: python numpy tensorflow

import matplotlib.pyplot as plt

x_arr = np.arange(-2, 4, 0.1)

g2 = tf.Graph()

with tf.Session(graph = g2) as sess:
    new_saver = tf.train.import_meta_graph(
    "./trained-model.meta")
    
    new_saver.restore(sess, "./trained-model")
    
    y_arr = sess.run("y_hat:0", 
                     feed_dict = {"tf_x:0", x_arr})
    
plt.figure()
plt.plot(x_train, y_train, "bo")
plt.plot(x_test, y_test, "bo", alpha = 0.3)
plt.plot(x_arr, y_arr.T[:,0], "-r", lw = 3)
plt.show()


输出



INFO:tensorflow:从./trained-model恢复参数

TypeError跟踪(最近一次通话最近) 在 12 13 y_arr = sess.run(“ y_hat:0”, ---> 14 feed_dict = {“ tf_x:0”,x_arr}) 15 16 plt.figure()

TypeError:不可散列的类型:'numpy.ndarray'


1 个答案:

答案 0 :(得分:0)

您需要将x_arr转换为张量类型。您可以通过tf.convert_to_tensor(x_arr)进行此操作。

来源:convert_to_tensor documentation

相关问题