How to combine two lists to 2D array in Python

2 Answers

0 votes
import numpy as np

lst1 = [5, 8, 1, 0]
lst2 = [7, 2, 3, 9]

arr2d = np.array([lst1, lst2])

print(arr2d)
  
  
  
  
'''
run:
  
[[5 8 1 0]
 [7 2 3 9]]

'''

 



answered Aug 9, 2022 by avibootz
0 votes
import numpy as np

lst1 = [5, 8, 1, 0]
lst2 = [7, 2, 3, 9]

arr2d = np.array(list(zip(lst1, lst2)))

print(arr2d)
  
  
  
  
'''
run:
  
[[5 7]
 [8 2]
 [1 3]
 [0 9]]

'''

 



answered Aug 9, 2022 by avibootz
...