Splits a tensor into sub tensors.
Aliases:
tf.compat.v1.split
tf.compat.v2.split
tf.split(
value,
num_or_size_splits,
axis=0,
num=None,
name='split'
)
Used in the guide:
M
as
ki
ng
a
nd
p
ad
di
ng
w
it
hK
e
ra
s``
Used in the tutorials:
C
on
vo
lu
ti
on
al
V
ar
ia
ti
on
al
A
ut
oe
nc
od
er
Ifnum_or_size_splits
is an integer, thenvalue
is split along dimensionaxis
intonum_split
smaller tensors. This requires thatnum_split
evenly dividesvalue
.shape[axis
]. Ifnum_or_size_splits
i
s a 1-D Tensor (or li
st), we calli
tsize_splits
andvalue
i
s spli
ti
nto len(size_splits
) elements. The shape of thei
-th element has the same si
ze as thevalue
except along di
mensi
onaxis
where the si
zei
ssize_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
: TheTensor
to split.num_or_size_splits
: Either an integer indicating the number of splits along split_dim or a 1-D integerTensor
or Python list containing the sizes of each output tensor along split_dim. If a scalar then it must evenly dividevalue
.shape[axis]; otherwise the sum of sizes along the split dimension must match that of thevalue
.
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
: Ifnum
is unspecified and cannot be inferred.