numpy regarding the array merge, split, and dimensionality reduction

Array merge numpy:

1.stack function, after the merger, +1 array dimension, in fact, the array will be merged to form a new array in accordance with a certain axis.

np.ones = A ((5,3 )) 
    B = np.zeros ((5,3 )) 
    C = np.stack ((A, B), Axis =. 1 )
     Print (c.shape) # of dimension 5,2,3, increasing a dimension in the direction of axis = 1

2.hstack function, the array 2 to the horizontal mosaic array 1

3.vstack function, the array 2 perpendicular to the lower splicing array 1.

4.column_stack () function is equivalent to hstack function.

5.row_stack () function, a function equivalent to vstack

numpy reduced to an array of one-dimensional:

flatten(),ravel()

a=np.ones((5,3))
b=np.zeros((5,3))
c=np.stack((a,b),axis=1)
print(c.shape)

Guess you like

Origin www.cnblogs.com/xuehaiwuya0000/p/11669104.html