此函数沿指定的轴将数组划分为子数组。该函数具有三个参数。

numpy.split(ary, indices_or_sections, axis)
Sr.No. Parameter & 描述
1

ary

要拆分的输入数组

2

indices_or_sections

可以是整数,指示要从输入数组创建的大小相等的子数组的数量。

3

axis

默认为0

import numpy as np 
a = np.arange(9) 

print 'First array:' 
print a 
print '\n'  

print 'Split the array in 3 equal-sized subarrays:' 
b = np.split(a,3) 
print b 
print '\n'  

print 'Split the array at positions indicated in 1-D array:' 
b = np.split(a,[4,7])
print b 

其输出如下-

First array:
[0 1 2 3 4 5 6 7 8]

Split the array in 3 equal-sized subarrays:
[array([0, 1, 2]), array([3, 4, 5]), array([6, 7, 8])]

Split the array at positions indicated in 1-D array:
[array([0, 1, 2, 3]), array([4, 5, 6]), array([7, 8])]

参考链接

https://www.learnfk.com/numpy/numpy-split.html