merge
np.newaxis
import numpy as np A = np.array ([l, 2,3 ] ) [:, np.newaxis] # into the column vector B = np.array ([4,5,6 ] ) [:, np.newaxis] # into column vector C = np.vstack ((A, B)) # Vertical Stack D = np.hstack ((A, B)) # Horizontal Stack Print (a.shape, b.shape) # ((3,1), (3, 1)) Print (c.shape) # (6, 1) Print (d.shape) # (3,2)
np.concatenate
import numpy as np a=np.array([1,2,3])[:,np.newaxis] b=np.array([4,5,6])[:,np.newaxis] C = np.concatenate ((A, B, B, A)) Print (C) # by columns into D = np.concatenate ((A, B, B, A), Axis = 0) # arranged in the column were combined Print (D) E = np.concatenate ((A, B, B, A), Axis =. 1) # provided combined in a row, three rows and four columns Print (E)
Split
import numpy as np A = np.arange (12 is) .reshape ((3,4- )) Print (A) Print (np.split (A, 2, Axis =. 1)) # Vertical partial longitudinal section 2 Print (np.split (A, 3, Axis = 0)) # Horizontal lateral three parts Print (np.array_split (A, 3, Axis =. 1)) # longitudinal 3 portions Print (np.vsplit (A, 3)) # transversely divided into three groups Print (np.hsplit (A, 2)) # vertically divided into two groups