tf.slice 1

tf.slice

t = tf.constant([[[1, 1, 1], [2, 2, 2]],
                 [[3, 3, 3], [4, 4, 4]],
                 [[5, 5, 5], [6, 6, 6]]])
tf.slice(t, [1, 0, 0], [1, 1, 3])  # [[[3, 3, 3]]]
tf.slice(t, [1, 0, 0], [1, 2, 3])  # [[[3, 3, 3],
                                   #   [4, 4, 4]]]
tf.slice(t, [1, 0, 0], [2, 1, 3])  # [[[3, 3, 3]],
                                   #  [[5, 5, 5]]]

Here is what the above code is Doing:
1. tf.slice(input_, begin, size)
2. input_ is [[[1, 1, 1], [2, 2, 2]],
[[3, 3, 3], [4, 4, 4]],
[[5, 5, 5], [6, 6, 6]]].
3. begin is [1, 0, 0].
4. size is [1, 1, 3].
5. The output of the first tf.slice() is [[[3, 3, 3]]].
6. The output of the second tf.slice() is [[[3, 3, 3],
[4, 4, 4]]].
7. The output of the third tf.slice() is [[[3, 3, 3]],
[[5, 5, 5]]].

Similar Posts