Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Numpy zip function

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?

like image 733
Håkon Hægland Avatar asked Oct 04 '14 13:10

Håkon Hægland


1 Answers

Just use

x1, x2, x3 = np.vstack([x,y]).T
like image 139
Daniel Avatar answered Oct 18 '22 13:10

Daniel