repeat

Graph.repeat(input, repeats, axis=None, *, name=None)

Repeat elements of a tensor.

Parameters

  • input (np.ndarray or Tensor) – The tensor whose elements you want to repeat.
  • repeats (int or list [ int ]) – The number of times to repeat each element. If you pass a single int or singleton list, that number of repetitions is applied to each element. Otherwise, you must pass a list with the same length as input along the specified axis (or the same total length as input if you omit axis).
  • axis (int or None , optional) – The axis along which you want to repeat elements. If you omit this value then the input is first flattened, and the repetitions applied to the flattened tensor.
  • name (str or None , optional) – The name of the node.

Returns

The repeated tensor. The result has the same shape as input except along axis, where its size is either the sum of repeats (if repeats is a list with at least two elements) or the product of the original size along axis with repeats (if repeats is a single int or singleton list). If axis is None then the output is 1D, with the sizes as described above applied to the flattened input tensor.

Return type

Tensor

Examples

>>> x = np.array([1, 2, 3])
>>> y = np.array([[1, 2, 3], [4, 5, 6]])

Duplicate each entry in an array once.

>>> graph.repeat(x, 2, axis=0, name="a")
<Tensor: name="a", operation_name="repeat", shape=(6,)>
>>> result = bo.execute_graph(graph=graph, output_node_names="a")
>>> result["output"]["a"]["value"]
array([1, 1, 2, 2, 3, 3])

Create a new array with different repetitions for each element in the original array along its second dimension.

>>> graph.repeat(x, [2, 3, 4], axis=0, name="b")
<Tensor: name="b", operation_name="repeat", shape=(9,)>
>>> result = bo.execute_graph(graph=graph, output_node_names="b")
>>> result["output"]["b"]["value"]
array([1, 1, 2, 2, 2, 3, 3, 3, 3])

Duplicate each entry in an array along its second dimension.

>>> graph.repeat(y, 2, axis=1, name="c")
<Tensor: name="c", operation_name="repeat", shape=(2, 6)>
>>> result = bo.execute_graph(graph=graph, output_node_names="c")
>>> result["output"]["c"]["value"]
array([[1, 1, 2, 2, 3, 3],
       [4, 4, 5, 5, 6, 6]])

Create a new array with different repetitions for each element in the original array along its first dimension.

>>> graph.repeat(y, [2, 3], axis=0, name="d")
<Tensor: name="d", operation_name="repeat", shape=(5, 3)>
>>> result = bo.execute_graph(graph=graph, output_node_names="d")
>>> result["output"]["d"]["value"]
array([[1, 2, 3],
       [1, 2, 3],
       [4, 5, 6],
       [4, 5, 6],
       [4, 5, 6]])

Was this useful?