tf.split
Stay organized with collections
Save and categorize content based on your preferences.
Splits a tensor into sub tensors.
tf.split(
value, num_or_size_splits, axis=0, num=None, name='split'
)
If num_or_size_splits
is an integer, then value
is split along dimension
axis
into num_split
smaller tensors. This requires that num_split
evenly
divides value.shape[axis]
.
If num_or_size_splits
is a 1-D Tensor (or list), we call it size_splits
and value
is split into len(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 size_splits[i]
.
For example:
# 'value' is a tensor with shape [5, 30]
# Split 'value' into 3 tensors with sizes [4, 15, 11] along dimension 1
split0, split1, split2 = tf.split(value, [4, 15, 11], 1)
tf.shape(split0) # [5, 4]
tf.shape(split1) # [5, 15]
tf.shape(split2) # [5, 11]
# Split 'value' into 3 tensors along dimension 1
split0, split1, split2 = tf.split(value, num_or_size_splits=3, axis=1)
tf.shape(split0) # [5, 10]
Args |
value
|
The Tensor to split.
|
num_or_size_splits
|
Either an integer indicating the number of splits along
split_dim or a 1-D integer Tensor or Python list containing the sizes of
each output tensor along split_dim. If a scalar then it must evenly divide
value.shape[axis] ; otherwise the sum of sizes along the split dimension
must match that of the value .
|
axis
|
An integer or scalar int32 Tensor . 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_splits is a scalar returns num_or_size_splits Tensor
objects; if num_or_size_splits is a 1-D Tensor returns
num_or_size_splits.get_shape[0] Tensor objects resulting from splitting
value .
|
Raises |
ValueError
|
If num is unspecified and cannot be inferred.
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2020-10-01 UTC.
[null,null,["Last updated 2020-10-01 UTC."],[],[],null,["# tf.split\n\n\u003cbr /\u003e\n\n|------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------|\n| [TensorFlow 1 version](/versions/r1.15/api_docs/python/tf/split) | [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.0.0/tensorflow/python/ops/array_ops.py#L1642-L1710) |\n\nSplits a tensor into sub tensors.\n\n#### View aliases\n\n\n**Compat aliases for migration**\n\nSee\n[Migration guide](https://www.tensorflow.org/guide/migrate) for\nmore details.\n\n[`tf.compat.v1.split`](/api_docs/python/tf/split)\n\n\u003cbr /\u003e\n\n tf.split(\n value, num_or_size_splits, axis=0, num=None, name='split'\n )\n\nIf `num_or_size_splits` is an integer, then `value` is split along dimension\n`axis` into `num_split` smaller tensors. This requires that `num_split` evenly\ndivides `value.shape[axis]`.\n\nIf `num_or_size_splits` is a 1-D Tensor (or list), we call it `size_splits`\nand `value` is split into `len(size_splits)` elements. The shape of the `i`-th\nelement has the same size as the `value` except along dimension `axis` where\nthe size is `size_splits[i]`.\n\n#### For example:\n\n # 'value' is a tensor with shape [5, 30]\n # Split 'value' into 3 tensors with sizes [4, 15, 11] along dimension 1\n split0, split1, split2 = tf.split(value, [4, 15, 11], 1)\n tf.shape(split0) # [5, 4]\n tf.shape(split1) # [5, 15]\n tf.shape(split2) # [5, 11]\n # Split 'value' into 3 tensors along dimension 1\n split0, split1, split2 = tf.split(value, num_or_size_splits=3, axis=1)\n tf.shape(split0) # [5, 10]\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|----------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `value` | The `Tensor` to split. |\n| `num_or_size_splits` | Either an integer indicating the number of splits along split_dim or a 1-D integer `Tensor` or Python list containing the sizes of each output tensor along split_dim. If a scalar then it must evenly divide `value.shape[axis]`; otherwise the sum of sizes along the split dimension must match that of the `value`. |\n| `axis` | An integer or scalar `int32` `Tensor`. The dimension along which to split. Must be in the range `[-rank(value), rank(value))`. Defaults to 0. |\n| `num` | Optional, used to specify the number of outputs when it cannot be inferred from the shape of `size_splits`. |\n| `name` | A name for the operation (optional). |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| if `num_or_size_splits` is a scalar returns `num_or_size_splits` `Tensor` objects; if `num_or_size_splits` is a 1-D Tensor returns `num_or_size_splits.get_shape[0]` `Tensor` objects resulting from splitting `value`. ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ------ ||\n|--------------|-------------------------------------------------|\n| `ValueError` | If `num` is unspecified and cannot be inferred. |\n\n\u003cbr /\u003e"]]