Split an array into multiple sub-arrays as views into `ary`. Parameters ---------- ary : ndarray Array to be divided into sub-arrays. indices_or_sections : int or 1-D array If `indices_or_sections` is an integer, N, the array will be divided into N equal
(ary, indices_or_sections, axis=0)
| 779 | |
| 780 | @array_function_dispatch(_split_dispatcher) |
| 781 | def split(ary, indices_or_sections, axis=0): |
| 782 | """ |
| 783 | Split an array into multiple sub-arrays as views into `ary`. |
| 784 | |
| 785 | Parameters |
| 786 | ---------- |
| 787 | ary : ndarray |
| 788 | Array to be divided into sub-arrays. |
| 789 | indices_or_sections : int or 1-D array |
| 790 | If `indices_or_sections` is an integer, N, the array will be divided |
| 791 | into N equal arrays along `axis`. If such a split is not possible, |
| 792 | an error is raised. |
| 793 | |
| 794 | If `indices_or_sections` is a 1-D array of sorted integers, the entries |
| 795 | indicate where along `axis` the array is split. For example, |
| 796 | ``[2, 3]`` would, for ``axis=0``, result in |
| 797 | |
| 798 | - ary[:2] |
| 799 | - ary[2:3] |
| 800 | - ary[3:] |
| 801 | |
| 802 | If an index exceeds the dimension of the array along `axis`, |
| 803 | an empty sub-array is returned correspondingly. |
| 804 | axis : int, optional |
| 805 | The axis along which to split, default is 0. |
| 806 | |
| 807 | Returns |
| 808 | ------- |
| 809 | sub-arrays : list of ndarrays |
| 810 | A list of sub-arrays as views into `ary`. |
| 811 | |
| 812 | Raises |
| 813 | ------ |
| 814 | ValueError |
| 815 | If `indices_or_sections` is given as an integer, but |
| 816 | a split does not result in equal division. |
| 817 | |
| 818 | See Also |
| 819 | -------- |
| 820 | array_split : Split an array into multiple sub-arrays of equal or |
| 821 | near-equal size. Does not raise an exception if |
| 822 | an equal division cannot be made. |
| 823 | hsplit : Split array into multiple sub-arrays horizontally (column-wise). |
| 824 | vsplit : Split array into multiple sub-arrays vertically (row wise). |
| 825 | dsplit : Split array into multiple sub-arrays along the 3rd axis (depth). |
| 826 | concatenate : Join a sequence of arrays along an existing axis. |
| 827 | stack : Join a sequence of arrays along a new axis. |
| 828 | hstack : Stack arrays in sequence horizontally (column wise). |
| 829 | vstack : Stack arrays in sequence vertically (row wise). |
| 830 | dstack : Stack arrays in sequence depth wise (along third dimension). |
| 831 | |
| 832 | Examples |
| 833 | -------- |
| 834 | >>> import numpy as np |
| 835 | >>> x = np.arange(9.0) |
| 836 | >>> np.split(x, 3) |
| 837 | [array([0., 1., 2.]), array([3., 4., 5.]), array([6., 7., 8.])] |
| 838 |
searching dependent graphs…