简体   繁体   中英

Turning 2 one dimensional arrays into 1 two dimensional array Numpy Python

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]]

Try np.stack :

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

Output:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM