python - Tensorflow - 数据维度、占位符

标签 python machine-learning tensorflow

我是 Tensorflow 的初学者,如果我的问题很微不足道,我很抱歉,但我查看了文档和 Google,但找不到答案。 (我也为我的英语道歉)

我想做类似的事情

sess.run(train, {x:x_train, y:x_train}

其中 x_train 是一个大小为 3190 的数组,包含我的输入数据(维度为 60*4 的数组)

我的问题是,x 应该是:

x = tf.placeholder(tf.bool, [60,4])

x = tf.placeholder(tf.bool, [None,60,4])

第一个给出以下错误:

ValueError: Cannot feed value of shape (3190, 60, 4) for Tensor u'Placeholder:0', which has shape '(60, 4)'

如果我使用第二个,如果我想计算,我怎样才能用 0<=i<60 和 0<=j<4 达到 x[i][j]

tf.logical_and(x[i1][j1],x[i2][j2])

提前感谢您的回答。

最佳答案

一定要使用

x = tf.placeholder(tf.bool, [None,60,4])

供您逻辑和使用

x_flat = tf.reshape( x , [ -1 , 60*4 ] )
ij1 = tf.reshape( tf.one_hot( [i1*4+j1] , 60*4 , dtype=tf.float32 ) , [ 60*4 , 1 ] )
ij2 = tf.reshape( tf.one_hot( [i2*4+j2] , 60*4 , dtype=tf.float32 ) , [ 60*4 , 1 ] )

tf.logical_and( tf.matmul( x_flat , ij1 ) , tf.matmul( x_flat , ij2 ) )

关于python - Tensorflow - 数据维度、占位符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43834529/

相关文章:

machine-learning - 如何将集群标签列添加回原始数据帧 - python,用于监督学习

python - 运行基本 tensorflow 示例时出错

machine-learning - 使用机器学习来分析体育博彩

machine-learning - 在进行完全连接计算之前,Caffe 如何隐式对 blob 进行 reshape ?

python - numpy:索引问题

python - 更多 'Pythonic' alternate list shuffle 方式

python - 全局变量与局部变量的性能

email - 如何提取没有签名或引用文本的电子邮件正文

python - 在 keras 中使用 SparseCategoricalCrossEntropy 损失进行多类分类时,实际的类标签是什么?

python - 此日志记录到哪里?