data_x = [[i for i in range(1,11)]]
data_y = [[10*i for i in range(1,11)]]
x = tf.placeholder(tf.float32, shape=(1,10))
y = tf.placeholder(tf.float32, shape=(1,10))
c = tf.constant(100.)
cn = tf.concat([x,y], axis=0)
t = tf.transpose(cn)
f = tf.foldl(lambda a,y: a+y[0]+y[1], t, c)
with tf.Session() as sess:
res = sess.run(t, feed_dict={x: data_x, y: data_y})
print(res)
使用concat和转置并折叠0维,但它仅适用于相同类型。示例:
使用while循环:
顺便说一句,这也适用于TensorArray,而
tf.foldl
则不行。在相关问题 更多 >
编程相关推荐