采用numpy快速将两个矩阵或数组合并成一个数组:

import numpy as np

数组

a = [[1,2,3],[4,5,6]]

b = [[1,1,1],[2,2,2]]

1、数组纵向合并

1)

c = np.vstack((a,b))

c =

array([[1, 2, 3],
       [4, 5, 6],
       [1, 1, 1],
       [2, 2, 2]]

2)

c = np.r_[a,b]

c = array([[1, 2, 3],
       [4, 5, 6],
       [1, 1, 1],
       [2, 2, 2]])


2、数组横向合并

1)、

d = np.hstack((a,b))

d = array([[1, 2, 3, 1, 1, 1],
       [4, 5, 6, 2, 2, 2]])

2)、

d = np.c_[a,b]

d = array([[1, 2, 3, 1, 1, 1],

       [4, 5, 6, 2, 2, 2]])