0

How can I add 2 one dimensional arrays together into one 2 dimensional array. I want to add a and b together so that I get the expected output.

a = np.array([0,1,0,1,0,1])
b = np.array([38846,51599,51599,52598,290480,360467])

Expected Output

[[     0  38846]
 [     1  51599]
 [     0  51599]
 [     1  52598]
 [     0 290480]
 [     1 360467]]

1 Answer 1

1

Try np.stack:

print(np.stack([a, b], axis=1))

Output:

[[     0  38846]
 [     1  51599]
 [     0  51599]
 [     1  52598]
 [     0 290480]
 [     1 360467]]
Sign up to request clarification or add additional context in comments.

2 Comments

I think he wants to combine them as columns, np.stack([a, b], axis=1)
@hpaulj Oh thanks for the catch... I misread the question

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.