mxnet.np.hsplit

hsplit(ary, indices_or_sections)

Split an array into multiple sub-arrays horizontally (column-wise). This is equivalent to split with axis=0 if ary has one dimension, and otherwise that with axis=1.

Parameters
  • ary (ndarray) – Array to be divided into sub-arrays.

  • indices_or_sections (int, list of ints or tuple of ints.) – If indices_or_sections is an integer, N, the array will be divided into N equal arrays along axis. If such a split is not possible, an error is raised. If indices_or_sections is a list of sorted integers, the entries indicate where along axis the array is split. If an index exceeds the dimension of the array along axis, it will raises errors. so index must less than or euqal to the dimension of the array along axis.

Returns

  • sub-arrays (list of ndarrays) – A list of sub-arrays.

  • .. note::

    • If indices_or_sections is given as an integer, but a split does not result in equal division.It will raises ValueErrors.

    • If indices_or_sections is an integer, and the number is 1, it will raises an error. Because single output from split is not supported yet…

See also

split()

Split an array into multiple sub-arrays of equal size.

Examples

>>> x = np.arange(16.0).reshape(4, 4)
>>> x
array([[ 0.,  1.,  2.,  3.],
       [ 4.,  5.,  6.,  7.],
       [ 8.,  9., 10., 11.],
       [12., 13., 14., 15.]])
>>> np.hsplit(x, 2)
[array([[ 0.,  1.],
       [ 4.,  5.],
       [ 8.,  9.],
       [12., 13.]]),
array([[ 2.,  3.],
       [ 6.,  7.],
       [10., 11.],
       [14., 15.]])]
>>> np.hsplit(x, [3, 6])
[array([[ 0.,  1.,  2.],
       [ 4.,  5.,  6.],
       [ 8.,  9., 10.],
       [12., 13., 14.]]),
array([[ 3.],
       [ 7.],
       [11.],
       [15.]]),
array([], shape=(4, 0), dtype=float32)]
With a higher dimensional array the split is still along the second axis.
>>> x = np.arange(8.0).reshape(2, 2, 2)
>>> x
array([[[ 0.,  1.],
        [ 2.,  3.]],
       [[ 4.,  5.],
        [ 6.,  7.]]])
>>> np.hsplit(x, 2)
[array([[[ 0.,  1.]],
        [[ 4.,  5.]]]),
 array([[[ 2.,  3.]],
        [[ 6.,  7.]]])]
If ``ary`` has one dimension, 'axis' = 0.
>>> x = np.arange(4)
array([0., 1., 2., 3.])
>>> np.hsplit(x, 2)
[array([0., 1.]), array([2., 3.])]
If you want to produce an empty sub-array, you can see an example.
>>> np.hsplit(x, [2, 2])
[array([0., 1.]), array([], dtype=float32), array([2., 3.])]