1>>>print(inspect.getsource(numpy.split))2@array_function_dispatch(_split_dispatcher)3defsplit(ary, indices_or_sections, axis=0):4"""
5 Split an array into multiple sub-arrays as views into `ary`.
67 Parameters
8 ----------
9 ary : ndarray
10 Array to be divided into sub-arrays.
11 indices_or_sections : int or 1-D array
12 If `indices_or_sections` is an integer, N, the array will be divided
13 into N equal arrays along `axis`. If such a split is not possible,
14 an error is raised.
1516 If `indices_or_sections` is a 1-D array of sorted integers, the entries
17 indicate where along `axis` the array is split. For example,
18 ``[2, 3]`` would, for ``axis=0``, result in
1920 - ary[:2]
21 - ary[2:3]
22 - ary[3:]
2324 If an index exceeds the dimension of the array along `axis`,
25 an empty sub-array is returned correspondingly.
26 axis : int, optional
27 The axis along which to split, default is 0.
2829 Returns
30 -------
31 sub-arrays : list of ndarrays
32 A list of sub-arrays as views into `ary`.
3334 Raises
35 ------
36 ValueError
37 If `indices_or_sections` is given as an integer, but
38 a split does not result in equal division.
3940 See Also
41 --------
42 array_split : Split an array into multiple sub-arrays of equal or
43 near-equal size. Does not raise an exception if
44 an equal division cannot be made.
45 hsplit : Split array into multiple sub-arrays horizontally (column-wise).
46 vsplit : Split array into multiple sub-arrays vertically (row wise).
47 dsplit : Split array into multiple sub-arrays along the 3rd axis (depth).
48 concatenate : Join a sequence of arrays along an existing axis.
49 stack : Join a sequence of arrays along a new axis.
50 hstack : Stack arrays in sequence horizontally (column wise).
51 vstack : Stack arrays in sequence vertically (row wise).
52 dstack : Stack arrays in sequence depth wise (along third dimension).
5354 Examples
55 --------
56 >>> x = np.arange(9.0)
57 >>> np.split(x, 3)
58 [array([0., 1., 2.]), array([3., 4., 5.]), array([6., 7., 8.])]
5960 >>> x = np.arange(8.0)
61 >>> np.split(x, [3, 5, 6, 10])
62 [array([0., 1., 2.]),
63 array([3., 4.]),
64 array([5.]),
65 array([6., 7.]),
66 array([], dtype=float64)]
6768 """69try:70len(indices_or_sections)71except TypeError:72 sections = indices_or_sections
73 N = ary.shape[axis]74if N % sections:75raise ValueError(76'array split does not result in an equal division')77return array_split(ary, indices_or_sections, axis)