vstack

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

Stacks all the input tensors x along vertical axis. 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, int8, 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

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

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

>>> # vstack 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.vstack((x1, x2))
>>> print(out)
Tensor(shape=[2, 3], dtype=float32, place=Place(cpu), stop_gradient=True,
[[1., 2., 3.],
 [3., 4., 5.]])

>>> # vstack with 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.vstack((x1, x2))
>>> print(out)
Tensor(shape=[2, 3], dtype=float32, place=Place(cpu), stop_gradient=True,
[[1., 2., 3.],
 [3., 4., 5.]])