nlcpy.split
- nlcpy.split(ary, indices_or_sections, axis=0)[source]
Splits an array into multiple sub-arrays.
- Parameters
- aryndarray
Array to be divided into sub-arrays.
- indices_or_sectionsint or 1-D array
If indices_or_sections is an integer, N, the array will be divided into N equal arrays along axis. If such a split is not possible, an error is raised. If indices_or_sections is a 1-D array of sorted integers, the entries indicate where along axis the array is split. For example,
[2, 3]
would, foraxis=0
, result inary[:2]
ary[2:3]
ary[3:]
If an index exceeds the dimension of the array along axis, an empty sub-array is returned correspondingly.
- axisint, optional
The axis along which to split, default is 0.
- Returns
- A list of sub-arrays.
See also
hsplit
Splits an array into multiple sub-arrays horizontally (column-wise).
vsplit
Splits an array into multiple sub-arrays vertically (row-wise).
concatenate
Joins a sequence of arrays along an existing axis.
stack
Joins a sequence of arrays along a new axis.
hstack
Stacks arrays in sequence horizontally (column wise).
vstack
Stacks arrays in sequence vertically (row wise).
Examples
>>> import nlcpy as vp >>> x = vp.arange(9.0) >>> vp.split(x, 3) [array([0., 1., 2.]), array([3., 4., 5.]), array([6., 7., 8.])]
>>> x = vp.arange(6) >>> vp.split(x, [3, 4, 7]) [array([0, 1, 2]), array([3]), array([4, 5]), array([], dtype=int64)]