Numpy zip function

Håkon Hægland picture Håkon Hægland · Oct 4, 2014 · Viewed 12.9k times · Source

If I have two numpy 1D arrays, for example

x=np.array([1,2,3])
y=np.array([11,22,33])

How can I zip these into Numpy 2D coordinates arrays? If I do:

x1,x2,x3=zip(*(x,y))

The results are of type list, not Numpy arrays. So I have do

x1=np.asarray(x1)

and so on.. Is there a simpler method, where I do not need to call np.asarray on each coordinate? Is there a Numpy zip function that returns Numpy arrays?

Answer

Daniel picture Daniel · Oct 4, 2014

Just use

x1, x2, x3 = np.vstack([x,y]).T