numpy数组的合并
-
按行合并
import numpy as np
A = np.array([1, 1, 1])
B = np.array([2, 2, 2])
print(np.vstack((A, B)))
# 按行合并
C = np.vstack((A, B))
print(A.shape, B.shape, C.shape)
#result
[[1 1 1]
[2 2 2]]
(3,) (3,) (2, 3)
-
首尾合并
# 首尾合并
D = np.hstack((A, B))
print(A.shape, B.shape, D.shape)
print(A[np.newaxis, :])
print(np.concatenate((A, B, B, A)))
#result
(3,) (3,) (6,)
[[1 1 1]]
[1 1 1 2 2 2 2 2 2 1 1 1]
来源:CSDN
作者:ZhengJohn
链接:https://blog.csdn.net/qq_38336343/article/details/104600740