column_stack

paddle. column_stack ( x, name=None ) [source]

Stacks all the input tensors x along horizontal axis. Each tensor in x will be first reshaped into (tensor.numel(), 1) if tensor.ndim < 2 before being stacked. All tensors must be of the same dtype.

Parameters
  • x (list[Tensor]|tuple[Tensor]) – Input x can be a list or tuple of tensors, the Tensors in x must be of the same shape and dtype. Supported data types: float16, float32, float64, int32, int64 or bfloat16.

  • name (str, optional) – Name for the operation (optional, default is None). For more information, please refer to Name.

Returns

Tensor, The stacked tensor with same data type as input.

Examples

>>> import paddle

>>> # column_stack with 0-D tensors
>>> x1 = paddle.to_tensor(1.0)
>>> x2 = paddle.to_tensor(2.0)
>>> out = paddle.column_stack((x1, x2))
>>> print(out)
Tensor(shape=[1, 2], dtype=float32, place=Place(cpu), stop_gradient=True,
[[1., 2.]])

>>> # column_stack mix with 1-D & 2-D tensors
>>> x1 = paddle.to_tensor([[1.0], [2.0], [3.0]])
>>> x2 = paddle.to_tensor([3.0, 4.0, 5.0])
>>> out = paddle.column_stack((x1, x2))
>>> print(out)
Tensor(shape=[3, 2], dtype=float32, place=Place(cpu), stop_gradient=True,
[[1., 3.],
 [2., 4.],
 [3., 5.]])

>>> # column_stack with 3-D tensors
>>> x1 = paddle.to_tensor([[[1.0, 2.0], [3.0, 4.0]]])
>>> x2 = paddle.to_tensor([[[3.0, 4.0], [5.0, 6.0]]])
>>> out = paddle.column_stack((x1, x2))
>>> print(out)
Tensor(shape=[1, 4, 2], dtype=float32, place=Place(cpu), stop_gradient=True,
[[[1., 2.],
  [3., 4.],
  [3., 4.],
  [5., 6.]]])