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]]
Sign up to request clarification or add additional context in comments.

2 Comments

I am hoping to keep it as a numpy array. Is that possible?
Yes, np.vstack((a,b)).T returns a numpy array.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.