Concatenate two arrays (lists) in Python


Set up arrays

list_one = [7, 6, 5]
list_two = [4, 3, 2]

Concatenate arrays horizontally

#horizontally
merged_list = list_one + list_two
merged_list
[7, 6, 5, 4, 3, 2]

Concatenate arrays vertically

#vertically
import numpy as np
np.vstack((list_one,list_two))
array([[7, 6, 5], [4, 3, 2]])


Ace your next data science interview

Get better at data science interviews by solving a few questions per week



Find a bug? Submit a suggested change on Github, or message me on Twitter.