例:data2如下左,想要拆成data3如下右,此时data2.shape=(9,2),data3.shape=(3,3,2)
data2 = np.arange(18).reshape(9,2)
Out[17]:
array([[ 0, 1],
[ 2, 3],
[ 4, 5],
[ 6, 7],
[ 8, 9],
[10, 11],
[12, 13],
[14, 15],
[16, 17]])
data3 = np.array(np.array_split(data2,3,axis=0)) # 3表示想要把数据分成3份,对应上图中3个颜色
Out[21]:
array([[[ 0, 1],
[ 2, 3],
[ 4, 5]],
[[ 6, 7],
[ 8, 9],
[10, 11]],
[[12, 13],
[14, 15],
[16, 17]]])
例:data3如下左,想要组合成data2如下右,此时data3.shape=(3,3,2),data2.shape=(9,2)
data3 = np.arange(18).reshape(3,3,2)
Out[85]:
array([[[ 0, 1],
[ 2, 3],
[ 4, 5]],
[[ 6, 7],
[ 8, 9],
[10, 11]],
[[12, 13],
[14, 15],
[16, 17]]])
data2 = data3.reshape(3*3,2)
Out[87]:
array([[ 0, 1],
[ 2, 3],
[ 4, 5],
[ 6, 7],
[ 8, 9],
[10, 11],
[12, 13],
[14, 15],
[16, 17]])