原文:https://blog.csdn.net/leviopku/article/details/82380710
keras.layers.concatenate([t1,t2],axis= )
t1,t2是需要拼接的变量,axis是拼接的轴
import numpy as np
import keras.backend as K
import tensorlfow as tf
t1 = K.variable(np.array([[[1, 2],[2,3]],[[4,4], [5,3]]]))
t2 = K.variable(np.array([[[7, 4],[8,4]],[[2,10],[15,11]]]))
d0 = K.concatenate([t1,t2], axis=0)
d1 = K.concatenate([t1,t2], axis=1)
d2 = K.concatenate([t1,t2], axis=2)
d3 = K.concatenate([t1,t2], axis=-1)
init = tf.global_variables_initializer()
with tf.Session() as sess:
sess.run(init)
print(sess.run(d1))
若是axis=0,则每个变量按第0轴取整体然后拼接,例如按0轴拼接t1和t2,t1的第0轴整体就是t1本身,t2同理,所以直接拼接得
到,按第1轴进行拼接则取t1[0],t2[0],然后拼接,按第2轴拼接则取t1[0][0],t2[0][0]然后拼接。
例如axis=1,t1[0]=[[1,2],[2,3]],t2[0]=[[7,4],[8,4]],拼接得到[[1,2],[2,3],[7,4],[8,4]]