垂直拆分:numpy.vsplit(数组,份数)->(数组片段)
In [20]: c = np.arange(1,13).reshape(6,2)
In [21]: c
Out[21]:
array([[ 1, 2],
[ 3, 4],
[ 5, 6],
[ 7, 8],
[ 9, 10],
[11, 12]])
In [22]: np.vsplit(c,3)
Out[22]:
[array([[1, 2],
[3, 4]]), array([[5, 6],
[7, 8]]), array([[ 9, 10],
[11, 12]])]
水平拆分:numpy.hsplit(数组,份数)->(数组片段)
In [27]: d =c.T
In [28]: d
Out[28]:
array([[ 1, 3, 5, 7, 9, 11],
[ 2, 4, 6, 8, 10, 12]])
In [29]: np.hsplit(d,3)
Out[29]:
[array([[1, 3],
[2, 4]]), array([[5, 7],
[6, 8]]), array([[ 9, 11],
[10, 12]])]
numpy.dsplit(数组,份数)->(数组片段)
In [32]: e = np.dstack((a,b))
In [33]: e
Out[33]:
array([[[11, 21],
[12, 22],
[13, 23]],
[[14, 24],
[15, 25],
[16, 26]],
[[17, 27],
[18, 28],
[19, 29]]])
In [35]: np.dsplit(e,2)
Out[35]:
[array([[[11],
[12],
[13]],
[[14],
[15],
[16]],
[[17],
[18],
[19]]]), array([[[21],
[22],
[23]],
[[24],
[25],
[26]],
[[27],
[28],
[29]]])]
接下来我们研究一下e的转置矩阵
In [42]: np.shape(f)
Out[42]: (2, 3, 3, 1)
In [44]: f[0]
Out[44]:
array([[[11],
[12],
[13]],
[[14],
[15],
[16]],
[[17],
[18],
[19]]])
In [45]: f[0].T
Out[45]:
array([[[11, 14, 17],
[12, 15, 18],
[13, 16, 19]]])
In [46]: f[0].T[0]
Out[46]:
array([[11, 14, 17],
[12, 15, 18],
[13, 16, 19]])
In [47]: f[0].T[0].T
Out[47]:
array([[11, 12, 13],
[14, 15, 16],
[17, 18, 19]])