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