# stack¶

`paddle.fluid.layers.``stack`(x, axis=0)[source]

This OP stacks all the inputs `x` along axis.

```Case 1:

Input:
x.shape = [1, 2]
x.data = [ [1.0 , 2.0 ] ]
x.shape = [1, 2]
x.data = [ [3.0 , 4.0 ] ]
x.shape = [1, 2]
x.data = [ [5.0 , 6.0 ] ]

Attrs:
axis = 0

Output:
Out.dims = [3, 1, 2]
Out.data =[ [ [1.0, 2.0] ],
[ [3.0, 4.0] ],
[ [5.0, 6.0] ] ]

Case 2:

Input:
x.shape = [1, 2]
x.data = [ [1.0 , 2.0 ] ]
x.shape = [1, 2]
x.data = [ [3.0 , 4.0 ] ]
x.shape = [1, 2]
x.data = [ [5.0 , 6.0 ] ]

Attrs:
axis = 1 or axis = -2

Output:
Out.shape = [1, 3, 2]
Out.data =[ [ [1.0, 2.0]
[3.0, 4.0]
[5.0, 6.0] ] ]
```
Parameters
• x (Variable|list(Variable)) – Input `x` can be a single Tensor, a `list` of Tensors. If `x` is a `list`, the shapes of all these Tensors must be the same. Supposing input is N dims Tensors \([d_0, d_1, ..., d_{n-1}]\), the output is N+1 dims Tensor \([d_0, d_1, d_{axis-1}, len(x), d_{axis}, ..., d_{n-1}]\). Support data types: float32, float64, int32, int64.

• axis (int, optional) – The axis along which all inputs are stacked. `axis` range is \([-(R+1), R+1)\). R is the first tensor of inputs. If `axis` < 0, \(axis=axis+rank(x)+1\). The default value of axis is 0.

Returns

The stacked Tensor, has same data type with input Tensors. Output dim is \(rank(x)+1\).

Return type

Variable

Examples

```import paddle.fluid as fluid