2

I have two numpy arrays such as:

a = np.array([1, 2, 3])

b = np.array([101, 102, 103 ])

I want to create a new array with shape (len(a), 2), such as

array([[1, 101], [2, 102], [3, 103]])

How can I do it with numpy?

2 Answers 2

2

This is so called column_stack

np.column_stack((a,b))
Out[309]: 
array([[  1, 101],
       [  2, 102],
       [  3, 103]])
Sign up to request clarification or add additional context in comments.

1 Comment

@Alex yw :-) happy coding :-)
1

Alternatively:

np.c_[a,b]

will do the job as well.

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.