Concatenation of one-dimensional arrays and two-dimensional arrays
NumPy has a lot of splicing functions. such as Hstack and Vstack. There are many such summary posts on the Internet. But the condition that two arrays can be spliced is the same dimension that satisfies two arrays. So when two-dimensional arrays and one-dimensional arrays are spliced, it is necessary to use Newaxis to convert one-dimensional arrays into two-dimensional arrays, that is, shape from (3,) to (3,1).
A = Np.array ([n/a]); b = Np.array ([[[1],[2],[3]]); #将一维数组a转化为二维数组a = A[:,np.newaxis];c = Np.concatenate ((b,a), Axis=1) Print c.shape//output as (3,2)
Two-dimensional arrays add rows
>>> A=np.array ([[2,4,3],[2,4,5]]) >>> B=np.array ([[8,7,6],[7,9,0]]) >>> C = np.concatenate ((b,a), axis=0) >>> CArray ([[8, 7, 6], [7, 9, 0], [2, 4, 3] , [2, 4, 5]]) >>> C = np.concatenate (b), axis=0) >>> CArray ([[2, 4, 3], [2, 4, 5], [8, 7, 6] , [7, 9, 0]])
Concatenation of one-dimensional arrays and two-dimensional arrays and addition of rows to two-dimensional arrays