split¶
- split(array: Any, indices_or_sections: int | list[int], axis: int = 0, xp: ModuleType | None = None) list[Any][source][source]¶
SciPy-specific replacement for
np.splitwithaxisandxp.- Parameters:
array (
array_like) – Array to be divided into sub-arrays.indices_or_sections (
intor1-D array) –- If
indices_or_sectionsis 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_sectionsis a 1-D array of sorted - integers, the entries indicate where along
axisthe array is split.
- integers, the entries indicate where along
- error is raised. If
- into N equal arrays along
- If
axis (
int, optional) – The axis along which to split, default is 0.xp (
array_namespace, optional) –- The array API namespace to use. If not provided, the namespace is
inferred from the arrays.
- Returns:
subarrays – A list of sub-arrays.
- Return type:
listofndarrays
Notes
This function is a thin wrapper around
array_api_compat.split.Examples
>>> import numpy as np >>> x = np.arange(9.0) >>> np.split(x, 3) [array([0., 1., 2.]), array([3., 4., 5.]), array([6., 7., 8.])] >>> x = np.arange(8.0).reshape(2, 4) >>> np.split(x, 2, axis=1) [array([[0., 1.], [4., 5.]]), array([[2., 3.], [6., 7.]])]