split(input, num_or_sections, dim=-1, name=None)
Split the input tensor into multiple sub-Tensors.
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_sectionsis an integer, then the integer indicates the number of equal sized sub-Tensors that the Tensor will be divided into. If
num_or_sectionsis 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’
dimdimension orderly. The length of the list mustn’t be larger than the Tensor’s size of
dim (int32|Varible, optional) – A scalar with type
Tensorwith shape  and type
int32. 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 .
The list of segmented Tensor variables.
- Return type
TypeError– num_or_sections is not int, list or tuple.
TypeError– dim is not int or Variable.
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]