Numpy

Numpy (8)

알 수 없는 사용자 2022. 7. 28. 20:28
728x90

How to stack two arrays vertically?

a = np.arange(10).reshape(2,-1)
b = np.repeat(1, 10).reshape(2,-1)

# Answers
# 1:
np.concatenate([a, b], axis=0)

# 2:
np.vstack([a, b])

# 3:
np.r_[a, b]

# output
array([[0, 1, 2, 3, 4],
       [5, 6, 7, 8, 9],
       [1, 1, 1, 1, 1],
       [1, 1, 1, 1, 1]])