Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/337.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在tensorflow中,如何使用占位符';喂食前的s值?_Python_Tensorflow - Fatal编程技术网

Python 在tensorflow中,如何使用占位符';喂食前的s值?

Python 在tensorflow中,如何使用占位符';喂食前的s值?,python,tensorflow,Python,Tensorflow,TensorFlow新手,现在我需要在输入前使用占位符中的值,类似于: tensor = tf.placeholder(tf.float32, [None, 3]) Mat_items = tf.Variable(tf.random_normal([10,10])) Mat_users = tf.Variable(tf.random_normal([10,10])) item_index = tensor[:, 0] user_index = tensor[:, 1] rating = tens

TensorFlow新手,现在我需要在输入前使用占位符中的值,类似于:

tensor = tf.placeholder(tf.float32, [None, 3])
Mat_items = tf.Variable(tf.random_normal([10,10]))
Mat_users = tf.Variable(tf.random_normal([10,10]))
item_index = tensor[:, 0]
user_index = tensor[:, 1]
rating = tensor[:, 2]
Val = Mat_items[item_index, :]-Mat_users[user_index, :]
张量是一个占位符,有N行3列,第一列和第二列分别是Mat_项和Mat_用户的索引,Mat_项Mat_用户是需要索引的变量。
运行它绝对会抛出一个错误,因为条目索引和用户索引在馈送之前都是张量而不是数字。 所以我想知道Tensorflow能否实现这个需求? 任何建议都将不胜感激!:)

========================================================================= 除了我的问题:
Val
依赖于
Tensor
中的某些列,就像第一列和第二列一样。因此,当我创建图形时,我会编写代码

Val = Mat_items[item_index, :]-Mat_users[user_index, :]
item\u index和user\u index是tensor的切片,它们也是类型
tensor
。它会抛出错误。我不知道如何在TensorFlow中实现这个需求

========================================================================= 我们已经找到了解决方案:

tensor = tf.placeholder(tf.float32, [None, 3])
Mat_items = tf.Variable(tf.random_normal([10,10]))
Mat_users = tf.Variable(tf.random_normal([10,10]))
for each in range(batch_number):
    item_ind, user_ind = tensor[each, 2], tensor[each, 1]
    rating = tensor[each, 1]
    Val = Mat_item[item_ind, 0]*Mat_user[user_ind, 0]*rating

上面的代码在构建图形时似乎很有效,即使使用少量数据集(批量大小约为1000,并且只有一批用于测试),构建图形大约需要78秒,我不确定这是否正常?

您的问题似乎很模糊,但我想您的问题是如何将值放入占位符中。如果要从
Val
获取输出,必须使用输入补充
tensor
,因为默认情况下它不包含任何值
Val
还依赖于
tensor
来计算其输出。您的输入必须与
张量
的大小相同。(在本例中,假设您的输入是随机噪声
input_tensor=numpy.random.uniform(-1,1,size=(None,3))
,其中None是您必须指定的值

因此,在开始会话后,执行
output=sess.run(Val,feed\u dict={tensor:input\u tensor})
output
将是您的结果

是的,Val依赖于张量。具体来说,Val依赖于张量的某些列中的值,因为这些列中的值是Val的索引。但是如果我创建像
Val=Mat_items[item_index,:]-Mat_users[user_index,:]
这样的图形,我的问题会更清楚吗?