MCPcopy Create free account
hub / github.com/numpy/numpy / vsplit

Function vsplit

numpy/lib/shape_base.py:944–989  ·  view source on GitHub ↗

Split an array into multiple sub-arrays vertically (row-wise). Please refer to the ``split`` documentation. ``vsplit`` is equivalent to ``split`` with `axis=0` (default), the array is always split along the first axis regardless of the array dimension. See Also --------

(ary, indices_or_sections)

Source from the content-addressed store, hash-verified

942
943@array_function_dispatch(_hvdsplit_dispatcher)
944def vsplit(ary, indices_or_sections):
945 """
946 Split an array into multiple sub-arrays vertically (row-wise).
947
948 Please refer to the ``split`` documentation. ``vsplit`` is equivalent
949 to ``split`` with `axis=0` (default), the array is always split along the
950 first axis regardless of the array dimension.
951
952 See Also
953 --------
954 split : Split an array into multiple sub-arrays of equal size.
955
956 Examples
957 --------
958 >>> x = np.arange(16.0).reshape(4, 4)
959 >>> x
960 array([[ 0., 1., 2., 3.],
961 [ 4., 5., 6., 7.],
962 [ 8., 9., 10., 11.],
963 [12., 13., 14., 15.]])
964 >>> np.vsplit(x, 2)
965 [array([[0., 1., 2., 3.],
966 [4., 5., 6., 7.]]), array([[ 8., 9., 10., 11.],
967 [12., 13., 14., 15.]])]
968 >>> np.vsplit(x, np.array([3, 6]))
969 [array([[ 0., 1., 2., 3.],
970 [ 4., 5., 6., 7.],
971 [ 8., 9., 10., 11.]]), array([[12., 13., 14., 15.]]), array([], shape=(0, 4), dtype=float64)]
972
973 With a higher dimensional array the split is still along the first axis.
974
975 >>> x = np.arange(8.0).reshape(2, 2, 2)
976 >>> x
977 array([[[0., 1.],
978 [2., 3.]],
979 [[4., 5.],
980 [6., 7.]]])
981 >>> np.vsplit(x, 2)
982 [array([[[0., 1.],
983 [2., 3.]]]), array([[[4., 5.],
984 [6., 7.]]])]
985
986 """
987 if _nx.ndim(ary) < 2:
988 raise ValueError('vsplit only works on arrays of 2 or more dimensions')
989 return split(ary, indices_or_sections, 0)
990
991
992@array_function_dispatch(_hvdsplit_dispatcher)

Callers 2

test_1D_arrayMethod · 0.90
test_2D_arrayMethod · 0.90

Calls 2

ndimMethod · 0.80
splitFunction · 0.70

Tested by 2

test_1D_arrayMethod · 0.72
test_2D_arrayMethod · 0.72