Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Numpy array creation from multiple lists

I am learning more about numpy and need help creating an numpy array from multiple lists. Say I have 3 lists,

a = [1, 1, 1] 
b = [2, 2, 2] 
c = [3, 3, 3] 

How can I create a new numpy array with each list as a column? Meaning that the new array would be [[1, 2, 3], [1, 2, 3], [1, 2, 3]]. I know how to do this by looping through the lists but I am not sure if there is an easier way to accomplish this. The numpy concatenate function seems to be close but I couldn't figure out how to get it to do what I'm after. Thanks

like image 734
User 965 Avatar asked Oct 30 '25 05:10

User 965


1 Answers

Try with np.column_stack:

d = np.column_stack([a, b, c])
like image 122
Longwen Ou Avatar answered Nov 01 '25 19:11

Longwen Ou



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!