1、concat的操作是将矩阵逐行拼起来,或者逐列拼起来:
import tensorflow as tf
t1 = [[1,2,3], [4,5,6]]
t2 = [[7,8,9], [10,11,12]]
sess = tf.Session()
print (sess.run(tf.concat(1, [t1, t2])))
结果:concat(1,[t1,t2])进行逐行拼凑,在LSTM中很经常用,每个时刻的输入都要产生输出,然后我们要将输出逐行拼起来,形成整个num_steps个时刻的输出
[[ 1 2 3 7 8 9]
[ 4 5 6 10 11 12]]
import tensorflow as tf
t1 = [[1,2,3], [4,5,6]]
t2 = [[7,8,9], [10,11,12]]
sess = tf.Session()
print (sess.run(tf.concat(0, [t1, t2])))
结果:tf.concat(0, [t1, t2])进行逐列输出
[[ 1 2 3]
[ 4 5 6]
[ 7 8 9]
[10 11 12]]
===============================================================================================================================
2、reshape的操作
import tensorflow as tf
tensor = tf.constant([1, 2, 3, 4, 5, 6, 7,8])
sess = tf.Session()
sess.run(tf.initialize_all_variables())
print('--------------')
print(sess.run(tensor))
tensorReshape = tf.reshape(tensor,[2,4])
print('---------------------')
print(sess.run(tensorReshape))
tensorReshape = tf.reshape(tensor,[-1,2,2])
print('---------------------')
print(sess.run(tensorReshape))
结果:
--------------
[1 2 3 4 5 6 7 8]
---------------------
[[1 2 3 4]
[5 6 7 8]]
---------------------
[[[1 2]
[3 4]]
[[5 6]
[7 8]]]
说明:
所以-1,就是缺省值,就是先以你们合适,到时总数除以你们几个的乘积,我该是几就是几
===============================================================================================================================