mindspore.ops.SplitV
- class mindspore.ops.SplitV(size_splits, split_dim, num_split)[source]
Splits the input tensor into num_split tensors along the given dimension.
The input_x tensor will be split into sub-tensors with individual shapes given by size_splits along the split dimension. This requires that input_x.shape(split_dim) is equal to the sum of size_splits.
The shape of input_x is
. The rank of input_x is R. Set the given split_dim as M, and . Set the given num_split as N, the given size_splits as , . The output is a list of tensor objects, for the -th tensor, it has the shape of . is the -th dimension of the -th tensor. Then, the shape of the output tensor is- Parameters
size_splits (Union[tuple, list]) – The list containing the sizes of each output tensor along the split dimension. Must sum to the dimension of value along split_dim. Can contain one -1 indicating that dimension is to be inferred.
split_dim (int) – The dimension along which to split. Must be in the range [-len(input_x.shape), len(input_x.shape)).
num_split (int) – The number of output tensors. Must be positive int.
- Inputs:
input_x (Tensor) - The shape of tensor is
.
- Outputs:
Tensor, a list of num_split Tensor objects with the shape
, . The data type is the same with input_x.
- Raises
TypeError – If input_x is not a Tensor.
TypeError – If size_splits is not a tuple or a list.
TypeError – If element of size_splits is not an int.
TypeError – If split_dim or num_split is not an int.
ValueError – If rank of the size_splits is not equal to num_split.
ValueError – If sum of the size_splits is not equal to the dimension of value along split_dim.
ValueError – If split_dim is out of the range [-len(input_x.shape), len(input_x.shape)).
ValueError – If the num_split is less than or equal to 0.
- Supported Platforms:
Ascend
Examples
>>> input_x = Tensor(np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]), mindspore.int32) >>> op = ops.SplitV(size_splits=[1, -1], split_dim=1, num_split=2) >>> output = op(input_x) >>> print(output) (Tensor(shape=[3, 1], dtype=Int32, value= [[1], [4], [7]]), Tensor(shape=[3, 2], dtype=Int32, value= [[2, 3], [5, 6], [8, 9]])) >>> input_x = Tensor(np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]), mindspore.int32) >>> op = ops.SplitV(size_splits=[2, 1], split_dim=0, num_split=2) >>> output = op(input_x) >>> print(output) (Tensor(shape=[2, 3], dtype=Int32, value= [[1, 2, 3], [4, 5, 6]]), Tensor(shape=[1, 3], dtype=Int32, value= [[7, 8, 9]]))