split¶
-
paddle.fluid.layers.
split
(input, num_or_sections, dim=-1, name=None)[source] Split the input tensor into multiple sub-Tensors.
- Parameters
input (Variable) – The input variable which is an N-D Tensor or LoDTensor, data type being float32, float64, int32 or int64.
num_or_sections (int|list|tuple) – If
num_or_sections
is an integer, then the integer indicates the number of equal sized sub-Tensors that the Tensor will be divided into. Ifnum_or_sections
is a list or tuple, the length of it indicates the number of sub-Tensors and the elements in it indicate the sizes of sub-Tensors’dim
dimension orderly. The length of the list mustn’t be larger than the Tensor’s size ofdim
.dim (int32|Varible, optional) – A scalar with type
int32
or aTensor
with shape [1] and typeint32
. The dimension along which to split. If \(dim < 0\), the dimension to split along is \(rank(input) + dim\). Default is -1.name (str, optional) – The default value is None. Normally there is no need for user to set this property. For more information, please refer to Name .
- Returns
The list of segmented Tensor variables.
- Return type
list(Variable)
- Raises
TypeError
– num_or_sections is not int, list or tuple.TypeError
– dim is not int or Variable.
Example
import paddle.fluid as fluid # input is a variable which shape is [3, 9, 5] input = fluid.data( name="input", shape=[3, 9, 5], dtype="float32") x0, x1, x2 = fluid.layers.split(input, num_or_sections=3, dim=1) # x0.shape [3, 3, 5] # x1.shape [3, 3, 5] # x2.shape [3, 3, 5] x0, x1, x2 = fluid.layers.split(input, num_or_sections=[2, 3, 4], dim=1) # x0.shape [3, 2, 5] # x1.shape [3, 3, 5] # x2.shape [3, 4, 5] x0, x1, x2 = fluid.layers.split(input, num_or_sections=[2, 3, -1], dim=1) # x0.shape [3, 2, 5] # x1.shape [3, 3, 5] # x2.shape [3, 4, 5]