dstack

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

Stacks all the input tensors x along depth 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

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

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

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