Tensorflow - 数据维度,占位符

时间:2017-05-07 17:28:34

标签: python machine-learning tensorflow

我是Tensorflow的完全初学者,如果我的问题很简单,我会道歉,但我已经查看了文档和谷歌,我找不到答案。 (我也为我的英语道歉)

我想做点什么

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&lt; 60&0&lt; = j&lt; 4的情况下达到x [i] [j]
tf.logical_and(x[i1][j1],x[i2][j2])

提前感谢您的回答。

1 个答案:

答案 0 :(得分:1)

使用

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 ) )