Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Numpy array conversion

Tags:

python

numpy

I've got 2 numpy arrays x1 and x2. Using python 3.4.3

x1 = np.array([2,4,4])
x2 = np.array([3,5,3])

I would like to a numpy array like this:

[[2,3],[4,5],[4,3]]

How would i go about this?

like image 698
B.Smit Avatar asked Feb 22 '26 09:02

B.Smit


1 Answers

You can use numpy.column_stack:

In [40]: x1 = np.array([2,4,4])

In [41]: x2 = np.array([3,5,3])

In [42]: np.column_stack((x1, x2))
Out[42]: 
array([[2, 3],
       [4, 5],
       [4, 3]])
like image 95
Warren Weckesser Avatar answered Feb 23 '26 22:02

Warren Weckesser



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!