slice

dragon.vm.tensorflow.slice(
  input_,
  begin,
  size,
  name=None
)[source]

Select the elements according to the given sections.

The section is hinted by [begin[i], begin[i] + size[i]):

x = tf.constant([[[0, 1, 2], [3, 4, 5]]])
print(tf.slice(x, [0, 1, 2], [1, 1, 1]))  # [[[5]]]
print(x[0:1, 1:2:, 2:3])  # Equivalent

The size accepts value -1 or 0:

x = tf.constant([[[0, 1, 2], [3, 4, 5]]])

# Set ``0`` to squeeze dimensions with size 1
print(tf.slice(x, [0, 1, 2], [0, 0, 0]))  # 5

# Set ``-1`` to take all the remained elements
print(tf.slice(x, [0, 0, 0], [-1, -1, -1]))  # [[[0, 1, 2], [3, 4, 5]]]
Parameters:
  • input (dragon.Tensor) – The input tensor.
  • begin (Union[Sequence[int], dragon.Tensor]) – The start location for each dimension.
  • size (Union[Sequence[int], dragon.Tensor]) – The number of elements sliced from start.
  • name (str, optional) – The operation name.
Returns:

dragon.Tensor – The output tensor.