row_stack

paddle. row_stack ( x, name=None ) [源代码]

vstack 的别名。沿垂直轴堆叠输入 x 中的所有张量。所有张量必须具有相同的数据类型。

参数

  • x (list[Tensor]|tuple[Tensor]) - 输入 x 可以是张量的 list 或 tuple, x 中张量的数据类型必须相同。支持的数据类型: float16float32float64int32int64bfloat16

  • name (str,可选) - 具体用法请参见 Name,一般无需设置,默认值为 None。

返回

Tensor,与输入数据类型相同的堆叠张量。

代码示例

>>> import paddle

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

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

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

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