1、数据拆分
垂直拆分:numpy.vsplit(数组,份数)->(数组片段)
import numpy as np
c = np.arange(1,13).reshape(6,2)
print(c)
[[ 1 2]
[ 3 4]
[ 5 6]
[ 7 8]
[ 9 10]
[11 12]]
np.vsplit(c,3)
[array([[1, 2],
[3, 4]]), array([[5, 6],
[7, 8]]), array([[ 9, 10],
[11, 12]])]
水平拆分:numpy.hsplit(数组,份数)->(数组片段)
d=c.T
d
np.hsplit(d,3)
[array([[1, 3],
[2, 4]]), array([[5, 7],
[6, 8]]), array([[ 9, 11],
[10, 12]])]
numpy.dsplit(数组,份数)->(数组片段)
a=np.arange(11,20)
b=np.arange(21,30)
e = np.dstack((a,b))
np.dsplit(e,2)
[array([[[11],
[12],
[13],
[14],
[15],
[16],
[17],
[18],
[19]]]), array([[[21],
[22],
[23],
[24],
[25],
[26],
[27],
[28],
[29]]])]
|