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

Function split

numpy/lib/shape_base.py:792–866  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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

Callers 4

test_equal_splitMethod · 0.90
hsplitFunction · 0.70
vsplitFunction · 0.70
dsplitFunction · 0.70

Calls 1

array_splitFunction · 0.85

Tested by 1

test_equal_splitMethod · 0.72