# In tensorflow tf.slice and tf.gather Use of slicing functions

Time：2020-6-10

tf.slice (input_ , begin, size, name = none): extract a subset of continuous regions according to the specified subscript range

tf.gather (params, indices, validate_ Indexes = none, name = none): extract a subset from axis = 0 according to the specified subscript set, which is suitable for extracting a subset of discontinuous regions

Output:

``````
input = [[[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]]]

tf.gather(input, [0, 2]) ==> [[[1, 1, 1], [2, 2, 2]],
[[5, 5, 5], [6, 6, 6]]]``````

Suppose we want to extract [[[3, 3, 3]]] from the input. The output is 1 in the index of inputtaxis = 0, 0 in axis = 1, 0-2 in axis = 2, so begin = [1, 0, 0], size = [1, 1, 3].

Suppose we want to extract [[[3, 3, 3], [4, 4, 4]]] from the input, the output is 1 in the index of inputtaxis = 0, 0-1 in axis = 1, 0-2 in axis = 2, so begin = [1, 0, 0], size = [1, 2, 3].

Suppose we want to extract [[[3, 3, 3], [5, 5, 5]]] from the input. The output is 1-2 in the index of inputtaxis = 0, 0-2 in axis = 1, 0-2 in axis = 2, so begin = [1,0,0], size = [2,1,3].

Suppose we want to extract [[[1, 1, 1], [2, 2, 2]], [[5, 5, 5], [6, 6, 6]]] from the input, and the output is [0, 2] in the subscript of axis = 0 of the input, which is discontinuous and can be used tf.gather Extraction. Input [0] and input [2]

In the above tensorflow tf.slice and tf.gather The use of slicing function is all the content that Xiaobian shared with you. I hope you can give us a reference, and also hope you can support developepaer more.

## Swift advanced 08: closure & capture principle

closure closurecanCapture and storageOf any constants and variables defined in their contextquote, this is the so-calledClose and wrap those constants and variablesTherefore, it is called“closure”Swift can handle everything for youCaptured memory managementOperation of. Three forms of closure [global function is a special closure]: a global function is a closure that has a name but does […]