分割:
import numpy as np
a = np.arange(12).reshape((3,4))#创建一个矩阵
print(a)
print(np.split(a,3,axis = 0 ))#分割矩阵,按行分成三份
print(np.array_split(a,3,axis=1))#不均等分割,将4列分成三份
print(np.vsplit(a,3))#横向分成三块
print(np.hsplit(a,2))#纵向分成两块
运行结果如下:
[[ 0 1 2 3]
[ 4 5 6 7]
[ 8 9 10 11]]
[array([[0, 1, 2, 3]]), array([[4, 5, 6, 7]]), array([[ 8, 9, 10, 11]])]
[array([[0, 1],
[4, 5],
[8, 9]]), array([[ 2],
[ 6],
[10]]), array([[ 3],
[ 7],
[11]])]
[array([[0, 1, 2, 3]]), array([[4, 5, 6, 7]]), array([[ 8, 9, 10, 11]])]
[array([[0, 1],
[4, 5],
[8, 9]]), array([[ 2, 3],
[ 6, 7],
[10, 11]])]