|  TensorFlow 1 version |  View source on GitHub | 
Splits a tensor value into a list of sub tensors.
tf.split(
    value, num_or_size_splits, axis=0, num=None, name='split'
)
See also tf.unstack.
If num_or_size_splits is an integer,  then value is split along the
dimension axis into num_or_size_splits smaller tensors. This requires that
value.shape[axis] is divisible by num_or_size_splits.
If num_or_size_splits is a 1-D Tensor (or list), then value is split into
len(num_or_size_splits) elements. The shape of the i-th
element has the same size as the value except along dimension axis where
the size is num_or_size_splits[i].
For example:
x = tf.Variable(tf.random.uniform([5, 30], -1, 1))# Split `x` into 3 tensors along dimension 1s0, s1, s2 = tf.split(x, num_or_size_splits=3, axis=1)tf.shape(s0).numpy()array([ 5, 10], dtype=int32)# Split `x` into 3 tensors with sizes [4, 15, 11] along dimension 1split0, split1, split2 = tf.split(x, [4, 15, 11], 1)tf.shape(split0).numpy()array([5, 4], dtype=int32)tf.shape(split1).numpy()array([ 5, 15], dtype=int32)tf.shape(split2).numpy()array([ 5, 11], dtype=int32)
| Args | |
|---|---|
| value | The Tensorto split. | 
| num_or_size_splits | Either an integer indicating the number of splits along axisor a 1-D integerTensoror Python list containing the sizes of
each output tensor alongaxis. If a scalar, then it must evenly dividevalue.shape[axis]; otherwise the sum of sizes along the split axis
must match that of thevalue. | 
| axis | An integer or scalar int32Tensor. The dimension along which to
split. Must be in the range[-rank(value), rank(value)). Defaults to 0. | 
| num | Optional, used to specify the number of outputs when it cannot be
inferred from the shape of size_splits. | 
| name | A name for the operation (optional). | 
| Returns | |
|---|---|
| if num_or_size_splitsis a scalar returns a list ofnum_or_size_splitsTensorobjects; ifnum_or_size_splitsis a 1-D Tensor returnsnum_or_size_splits.get_shape[0]Tensorobjects resulting from splittingvalue. | 
| Raises | |
|---|---|
| ValueError | If numis unspecified and cannot be inferred. |