例子
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])]