split¶
- paddle.fluid.layers.nn. split ( input, num_or_sections, dim=- 1, name=None ) [source]
-
Split the input tensor into multiple sub-Tensors.
- Parameters
-
input (Tensor) – A N-D Tensor. The data type is bool, float16, float32, float64, int32 or int64.
num_or_sections (int|list|tuple) – If
num_or_sections
is int, then thenum_or_sections
indicates the number of equal sized sub-Tensors that theinput
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’ dimension orderly. The length of the list mustn’t be larger than theinput
‘s size of specified dim.dim (int|Tensor, optional) – The dimension along which to split, it can be a scalar with type
int
or aTensor
with shape [1] and data typeint32
orint64
. 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 Tensors.
- Return type
-
list(Tensor)
Example
import paddle.fluid as fluid # input is a Tensor which shape is [3, 9, 5] input = fluid.data( name="input", shape=[3, 9, 5], dtype="float32") out0, out1, out2 = fluid.layers.split(input, num_or_sections=3, dim=1) # out0.shape [3, 3, 5] # out1.shape [3, 3, 5] # out2.shape [3, 3, 5] out0, out1, out2 = fluid.layers.split(input, num_or_sections=[2, 3, 4], dim=1) # out0.shape [3, 2, 5] # out1.shape [3, 3, 5] # out2.shape [3, 4, 5] out0, out1, out2 = fluid.layers.split(input, num_or_sections=[2, 3, -1], dim=1) # out0.shape [3, 2, 5] # out1.shape [3, 3, 5] # out2.shape [3, 4, 5] # dim is negative, the real dim is (rank(input) + axis) which real # value is 1. out0, out1, out2 = fluid.layers.split(input, num_or_sections=3, dim=-2) # out0.shape [3, 3, 5] # out1.shape [3, 3, 5] # out2.shape [3, 3, 5]