Numpy
Numpy (9)
Jun's N
2022. 7. 29. 21:11
How to stack two arrays horizontally?
a = np.arange(10).reshape(2,-1)
b = np.repeat(1, 10).reshape(2,-1)
# Answers
# 1:
np.concatenate([a, b], axis=1)
# 2:
np.hstack([a, b])
# 3:
np.c_[a, b]
# output
array([[0, 1, 2, 3, 4, 1, 1, 1, 1, 1],
[5, 6, 7, 8, 9, 1, 1, 1, 1, 1]])
728x90