首页 > 解决方案 > 如何将列表输入到 tensorflow 中的 feed_dict 中?list的元素有不同的形状

问题描述

我想将一个列表传递给 feed_dict,但是我在这样做时遇到了麻烦。在我的代码中:

temp1=tf.placeholder(tf.float32, [10])
temp2=tf.placeholder(tf.float32, [10,30])
temp3=tf.placeholder(tf.float32, [5,15,8])
list1.append(temp1)
list1.append(temp2)
list1.append(temp3) 

其中 list1 被输入一个函数。根据网络:在 TensorFlow 中将列表输入到 feed_dict 的问题

我写代码:

data = [np.array(...), ...] ####data is the input of list1
sess.run(y, feed_dict={i: d for i, d in zip(list1, data)})

但我得到一个错误:无效的语法

我怎么解决这个问题?

我研究过网络:问题在 TensorFlow 中将列表输入 feed_dict它不能解决我的问题

标签: pythonlisttensorflow

解决方案


看起来您正在尝试将 python 函数与张量对象 (list1) 一起使用。for 循环可能不知道如何处理占位符。也许尝试:

字典 = dict(zip(list1, data))


推荐阅读