# mars.tensor.split¶

mars.tensor.split(ary, indices_or_sections, axis=0)[source]

Split a tensor into multiple sub-tensors.

Parameters
• ary (Tensor) – Tensor to be divided into sub-tensors.

• indices_or_sections (int or 1-D tensor) –

If indices_or_sections is an integer, N, the array will be divided into N equal tensors along axis. If such a split is not possible, an error is raised.

If indices_or_sections is a 1-D tensor of sorted integers, the entries indicate where along axis the array is split. For example, [2, 3] would, for axis=0, result in

• ary[:2]

• ary[2:3]

• ary[3:]

If an index exceeds the dimension of the tensor along axis, an empty sub-tensor is returned correspondingly.

• axis (int, optional) – The axis along which to split, default is 0.

Returns

sub-tensors – A list of sub-tensors.

Return type

list of Tensors

Raises

ValueError – If indices_or_sections is given as an integer, but a split does not result in equal division.

array_split

Split a tensor into multiple sub-tensors of equal or near-equal size. Does not raise an exception if an equal division cannot be made.

hsplit

Split into multiple sub-arrays horizontally (column-wise).

vsplit

Split tensor into multiple sub-tensors vertically (row wise).

dsplit

Split tensor into multiple sub-tensors along the 3rd axis (depth).

concatenate

Join a sequence of tensors along an existing axis.

stack

Join a sequence of tensors along a new axis.

hstack

Stack tensors in sequence horizontally (column wise).

vstack

Stack tensors in sequence vertically (row wise).

dstack

Stack tensors in sequence depth wise (along third dimension).

Examples

>>> import mars.tensor as mt

>>> x = mt.arange(9.0)
>>> mt.split(x, 3).execute()
[array([ 0.,  1.,  2.]), array([ 3.,  4.,  5.]), array([ 6.,  7.,  8.])]

>>> x = mt.arange(8.0)
>>> mt.split(x, [3, 5, 6, 10]).execute()
[array([ 0.,  1.,  2.]),
array([ 3.,  4.]),
array([ 5.]),
array([ 6.,  7.]),
array([], dtype=float64)]