Environment: Tensorfow 2.*

def concatenate(inputs, axis=-1, **kwargs):

Axis =n means stitching from the NTH dimension. For a three-dimensional matrix, the value of axis can be [-3, -2, -1, 0, 1, 2].

Below, 0 in depth, 1 in row, 2 in column

code

import numpy as np
import tensorflow as tf

t1 = tf.Variable(np.array([[[1, 2], [2, 3]], [[4, 4], [5, 3]]]))
t2 = tf.Variable(np.array([[[7, 4], [8, 4]], [[2, 10], [15, 11]]]))

d0 = tf.keras.layers.concatenate([t1, t2], axis=0)
d1 = tf.keras.layers.concatenate([t1, t2], axis=1)
d2 = tf.keras.layers.concatenate([t1, t2], axis=2)
d3 = tf.keras.layers.concatenate([t1, t2], axis=-1)

print(d0)
print(d1)
print(d2)
print(d3)
Copy the code

The output

Tf. Tensor ([[[1, 2], [2, 3]] [[4 4] [5 3]] [[4] 7 4 [8]] [[2] 10 11 [15]]], shape = (4, 2, 2), dtype = int32) # 4 representative depth, Similar to 4 pages tf. Tensor ([[[1, 2], [2, 3] [4] 7 4 [8]] [[4] 4 [3] 5 [2] 10 11 [15]]], shape = (2, 4, 2), dtype=int32) tf.Tensor( [[[ 1 2 7 4] [ 2 3 8 4]] [[ 4 4 2 10] [ 5 3 15 11]]], shape=(2, 2, 4), dtype=int32) tf.Tensor( [[[ 1 2 7 4] [ 2 3 8 4]] [[ 4 4 2 10] [ 5 3 15 11]]], shape=(2, 2, 4), dtype=int32) Process finished with exit code 0Copy the code

Dimension of the array

Print (np.arange(0,7,1,dtype=np.int16)) print(np.ones((2,3,4),dtype=np.int16))) Print (np.arange(0,10,2)) print(np.arange(0,10,2)) print(np.arange(0,10,2)) Print (np.random. Randint (0,3,(2,3)) print(np.random. Randint (0,3,(2,3)) print(np.linspace(-1,2,5)) print(np.randomCopy the code

The output

[0, 1, 2, 3, 4, 5 and 6] [[[1 1 1 1] [1 1 1 1] [1 1 1 1]] [[1 1 1 1] [1 1 1 1] [1 1 1 1]]] [[[0. 0. 0. 0.] [0. 0. 0. 0.] [0. 0. 0. 0.]] [[0. 0. 0. 0.] [0. 0. 0. 0.] [0. 0. 0. 0.]]] [[1.39069238 1.39069238 1.39069238 e-309 e-309 e-309] [ E-309 1.39069238E-309 1.39069238E-309]] [0 2 4 6 8] [-1. -0.25 0.5 1.25 2.] [1 0 1] [0 1 0]]Copy the code