Skip to content
Advertisement

Splicing NumPy arrays

I am having a problem splicing together two arrays. Let’s assume I have two arrays:

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

When I do vstack((a,b)) I get

[[1,2,3],[4,5,6]]

and if I do hstack((a,b)) I get:

[1,2,3,4,5,6]

But what I really want is:

[[1,4],[2,5],[3,6]]

How do I accomplish this without using for loops (it needs to be fast)?

Advertisement

Answer

column_stack.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement