2

I have two arrays of the form:

a = np.array([1,2,3])
b = np.array([4,5,6])

Is there a NumPy function which I can apply to these arrays to get the followng output?

[[1,4],[2,5][3,6]]
0

1 Answer 1

7
np.vstack((a,b)).T

returns

array([[1, 4],
       [2, 5],
       [3, 6]])

and

np.vstack((a,b)).T.tolist()

returns exactly what you need:

[[1, 4], [2, 5], [3, 6]]
2
  • I am hoping to keep it as a numpy array. Is that possible? Commented Apr 11, 2012 at 10:45
  • Yes, np.vstack((a,b)).T returns a numpy array. Commented Apr 11, 2012 at 10:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.