numpy.split

numpy.split(ary, indices_or_sections, axis=0)[源代码]

将数组拆分为多个子数组作为视图 ary .

参数
ary恩达雷

数组被划分为子数组。

indices_or_sectionsint或一维数组

如果 indices_or_sections 是一个整数,n,数组将被分成n个相等的数组 axis . 如果无法进行这种拆分,则会引发错误。

如果 indices_or_sections 是一个一维的已排序整数数组,这些项指示 axis 数组被拆分。例如, [2, 3] 会,为了 axis=0 结果

  • 阿利 [:2]

  • 阿利 [2:3]

  • 阿利 [3:]

如果索引超出了数组的维数, axis ,相应地返回空的子数组。

axis可选的

要沿其拆分的轴,默认值为0。

返回
sub-arrays日历列表

作为视图的子数组列表 ary .

加薪
ValueError

如果 indices_or_sections 以整数形式给出,但拆分不会导致等分。

参见

array_split

将一个数组拆分为大小相等或接近相等的多个子数组。如果不能进行等分,则不会引发异常。

hsplit

将数组水平拆分为多个子数组(按列)。

vsplit

将数组垂直拆分为多个子数组(按行)。

dsplit

沿第三轴(深度)将阵列拆分为多个子阵列。

concatenate

沿现有轴联接一系列数组。

stack

沿新轴连接一系列数组。

hstack

按水平顺序(按列)堆叠数组。

vstack

按顺序垂直堆叠数组(按行)。

dstack

按顺序深度(沿三维)堆叠数组。

实例

>>> 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)
>>> np.split(x, [3, 5, 6, 10])
[array([0.,  1.,  2.]),
 array([3.,  4.]),
 array([5.]),
 array([6.,  7.]),
 array([], dtype=float64)]