numpy 合并

import numpy as np

# 合并

A = np.array([1,1,1])
B = np.array([2,2,2])
C = np.vstack((A,B))
# 上下合并
print(A.shape)
print(C)
print(C.shape)
print('******************************')
# 左右合并
D = np.hstack((A,B))
print(D)
print(D.shape)
print('******************************')
# 改变维度
print(A[:,np.newaxis])
print('******************************')

E = np.concatenate((A,B,B,A),axis=0)
print(E)

结果:
(3,)
[[1 1 1]
[2 2 2]]
(2, 3)


[1 1 1 2 2 2]
(6,)


[[1]
[1]
[1]]


[1 1 1 2 2 2 2 2 2 1 1 1]

猜你喜欢

转载自blog.csdn.net/code_fighter/article/details/80373434