python np.concatenate()函数

numpy.concatenate()函数➡➡能够一次完成多个数组的拼接
python np.concatenate()函数_第1张图片
例如:

a = np.array([[[0,1],[2,3]],[[4,5],[6,7]]])
b = np.array([[[6,7],[8,9]],[[10,11],[12,13]]])
print(a)
print(b)
M = np.concatenate((a,b),axis=1)
N = np.concatenate([a,b],axis=1)
print(M)
print(N)

输出结果为:
数组a:

[[[ 0  1]
  [ 2  3]]
 [[ 4  5]
  [ 6  7]]]

数组b:

[[[ 6  7]
  [ 8  9]]
 [[10 11]
  [12 13]]]

M为:

[[[ 0  1]
  [ 2  3]
  [ 6  7]
  [ 8  9]]
 [[ 4  5]
  [ 6  7]
  [10 11]
  [12 13]]]

N亦为:

[[[ 0  1]
  [ 2  3]
  [ 6  7]
  [ 8  9]]
 [[ 4  5]
  [ 6  7]
  [10 11]
  [12 13]]]

可得:np.concatenate()函数里的中括号小括号没有区别!!!

另外,axis=0

L = np.concatenate([a,b],axis=0)
print(L)

输出L为:

[[[ 0  1]
  [ 2  3]]
 [[ 4  5]
  [ 6  7]]
 [[ 6  7]
  [ 8  9]]
 [[10 11]
  [12 13]]]

另外axis=2

K = np.concatenate([a,b],axis=0)
print(K)

输出K为:

[[[ 0  1  6  7]
  [ 2  3  8  9]
 [[ 4  5 10 11]
  [ 6  7 12 13]]]

你可能感兴趣的:(python,numpy)