Article From:https://www.cnblogs.com/lemon-rain/p/9061952.html

slice（）The function prototype is:

tf.slice(input_, begin, size, name=None)

The function has 4 parameters:

1，input_ ：The matrix input format of the picture.

2，begin ：The location of the interception (a point of the input matrix, usually in the form of [x, y, z]).

3，size ：The distance that is intercepted from the starting point to each dimension (usually in the form of [x, y, z]).

4，name ：The name of the tensor.

tensor(a,b,c)

tensor(z,y,x) The representation of a vector in three-dimensional coordinates, such as a three-dimensional coordinate axis. The order of the tf.slice () parameter is (Z, y, x).

Official website examples:

``````# 'input' is [[[1, 1, 1], [2, 2, 2]],
#             [[3, 3, 3], [4, 4, 4]],
#             [[5, 5, 5], [6, 6, 6]]]
tf.slice(input, [1, 0, 0], [1, 1, 3]) ==> [[[3, 3, 3]]]
tf.slice(input, [1, 0, 0], [1, 2, 3]) ==> [[[3, 3, 3],
[4, 4, 4]]]
tf.slice(input, [1, 0, 0], [2, 1, 3]) ==> [[[3, 3, 3]],
[[5, 5, 5]]]``````

Interpretation:

1，inputIt is a 3 dimensional vector as the input value of the tf.slice () function (the tensor to be intercepted).

2，The second parameter [1,0,0] is the starting point of the interception. Here is the first digit of the second row “3”.

3，There are 3 examples of the third parameters. (1) (3):

（1） [ 1,1,3 ] It is the intercept distance. The first dimension intercepts 1 distances, so we first cut out [[[3,3,3], [4,4,4]]]. The second dimension intercepts 1 distances, then cut out [[[3,3,3]] part. ThirdIntercepting 3 distances in one dimension, intercept all 3 elements and get the result.

（3）[ 2,1,3 ] The first dimension is 2.

[  [  [ 3,3,3 ] , [ 4,4,4 ] ,

[  [ 5,5,5 ] , [ 6,6,6 ] ] ]

This part. The second dimension is 1, and then intercepts one distance.

[  [  [ 3,3,3 ]  ,

[  [ 5,5,5 ] ] ]

This part. The third dimension cuts 3 distances, obtains the result, if cuts 2 distances, obtains:

[  [  [ 3,3 ]  ,

[  [ 5,5 ] ] ]

Note:

（1）In the third parameter, -1, such as [1, -1 and -1], can be used to represent the second and 3 dimensions from the beginning to the end.

（2）The multidimensional vectors should not be interpreted as lines, planes, bodies, or so. In that case, the above 3 dimensional points will correspond to errors. How many layers of symbol “[]” have the number of dimensions from outer to inner, and dimensions increase sequentially.