0

I have two numpy arrays:

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

and I want to concatenate them into two columns like,

1 4
2 5
3 6 

is there any way to do this without transposing or reshaping the arrays?

1

1 Answer 1

1

You can try:

a = np.array([1, 2, 3])
b = np.array([4, 5, 6])
c = np.concatenate((a[np.newaxis, :], b[np.newaxis, :]), axis = 0).T

And you get :

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

Best,

Sign up to request clarification or add additional context in comments.

Comments

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.