concatenate

Graph.concatenate(tensors, axis, *, name=None)

Concatenate a list of tensors along a specified dimension.

Parameters

  • tensors (list [ np.ndarray or Tensor ]) – The list of tensors that you want to concatenate. All of them must have the same shape in all dimensions except axis. You must pass at least two elements in this list.
  • axis (int) – The dimension along which you want to concatenate the tensors.
  • name (str or None , optional) – The name of the node.

Returns

The concatenated tensor.

Return type

Tensor

Notes

This node only concatenates on an existing axis, it does not create new axes. If you want to stack along a new axis or concatenate scalars, add a new axis to the tensors with [None].

Examples

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

Concatenate x and y along their first dimension.

>>> graph.concatenate(tensors=[x, y], axis=0, name="node_0")
<Tensor: name="node_0", operation_name="concatenate", shape=(3, 3)>
>>> result = bo.execute_graph(graph=graph, output_node_names="node_0")
>>> result["output"]["node_0"]["value"]
array([[1., 2., 3.],
       [4., 5., 6.],
       [7., 8., 9.]])

Concatenate two x arrays along their second dimension.

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

Was this useful?