MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / split

Function split

tensorflow/python/ops/array_ops.py:1631–1698  ·  view source on GitHub ↗

Splits a tensor into sub tensors. 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_spl

(value, num_or_size_splits, axis=0, num=None, name="split")

Source from the content-addressed store, hash-verified

1629
1630@tf_export("split")
1631def split(value, num_or_size_splits, axis=0, num=None, name="split"):
1632 """Splits a tensor into sub tensors.
1633
1634 If `num_or_size_splits` is an integer, then `value` is split along dimension
1635 `axis` into `num_split` smaller tensors. This requires that `num_split` evenly
1636 divides `value.shape[axis]`.
1637
1638 If `num_or_size_splits` is a 1-D Tensor (or list), we call it `size_splits`
1639 and `value` is split into `len(size_splits)` elements. The shape of the `i`-th
1640 element has the same size as the `value` except along dimension `axis` where
1641 the size is `size_splits[i]`.
1642
1643 For example:
1644
1645 ```python
1646 # 'value' is a tensor with shape [5, 30]
1647 # Split 'value' into 3 tensors with sizes [4, 15, 11] along dimension 1
1648 split0, split1, split2 = tf.split(value, [4, 15, 11], 1)
1649 tf.shape(split0) # [5, 4]
1650 tf.shape(split1) # [5, 15]
1651 tf.shape(split2) # [5, 11]
1652 # Split 'value' into 3 tensors along dimension 1
1653 split0, split1, split2 = tf.split(value, num_or_size_splits=3, axis=1)
1654 tf.shape(split0) # [5, 10]
1655 ```
1656
1657 Args:
1658 value: The `Tensor` to split.
1659 num_or_size_splits: Either an integer indicating the number of splits along
1660 split_dim or a 1-D integer `Tensor` or Python list containing the sizes of
1661 each output tensor along split_dim. If a scalar then it must evenly divide
1662 `value.shape[axis]`; otherwise the sum of sizes along the split dimension
1663 must match that of the `value`.
1664 axis: An integer or scalar `int32` `Tensor`. The dimension along which to
1665 split. Must be in the range `[-rank(value), rank(value))`. Defaults to 0.
1666 num: Optional, used to specify the number of outputs when it cannot be
1667 inferred from the shape of `size_splits`.
1668 name: A name for the operation (optional).
1669
1670 Returns:
1671 if `num_or_size_splits` is a scalar returns `num_or_size_splits` `Tensor`
1672 objects; if `num_or_size_splits` is a 1-D Tensor returns
1673 `num_or_size_splits.get_shape[0]` `Tensor` objects resulting from splitting
1674 `value`.
1675
1676 Raises:
1677 ValueError: If `num` is unspecified and cannot be inferred.
1678 """
1679 size_splits = ops.convert_to_tensor(num_or_size_splits)
1680 if isinstance(num_or_size_splits,
1681 six.integer_types + (tensor_shape.Dimension,)):
1682 return gen_array_ops.split(
1683 axis=axis, num_split=num_or_size_splits, value=value, name=name)
1684
1685 if size_splits._rank() == 0:
1686 raise ValueError(
1687 "Rank-0 tensors are not supported as the num_or_size_splits argument "
1688 "to split. Argument provided: %s" % (num_or_size_splits,))

Callers

nothing calls this directly

Calls 3

splitMethod · 0.45
_rankMethod · 0.45
_shape_tupleMethod · 0.45

Tested by

no test coverage detected