On Fri, Mar 23, 2007 at 11:09:03AM -0400, Robert Pyle wrote: > > In [65]:concatenate((a.reshape(10,1),b.reshape(10,1)),axis=1) > > Out[65]: > > array([[ 0, -10], > > [ 1, -9], > > [ 2, -8], > > [ 3, -7], > > [ 4, -6], > > [ 5, -5], > > [ 6, -4], > > [ 7, -3], > > [ 8, -2], > > [ 9, -1]]) > > > > > > ? > > > > I thought there would be an easier way. Did I overlook something? > > What's wrong with zip? Or did *I* miss the point? (I'm just getting > the hang of numpy.)
If you use 'zip' you don't make use of numpy's fast array mechanisms. I attach some code you can run as a benchmark. From my ipython session: In [1]: run vsbench.py In [2]: timeit using_vstack(x,y) 1000 loops, best of 3: 997 µs per loop In [3]: timeit using_zip(x,y) 10 loops, best of 3: 503 ms per loop In [4]: timeit using_custom_iteration(x,y) 1000 loops, best of 3: 1.64 ms per loop Cheers Stéfan
import numpy as N x = N.random.random(100000) y = N.random.random(100000) def using_vstack(*args): return N.vstack(args).T def using_zip(*args): return N.array(zip(*args)) def using_custom_iteration(*args): x = N.empty((len(args[0]),len(args))) for i,vals in enumerate(args): x[:,i] = vals return x check = N.vstack((x,y)).T assert N.all(using_vstack(x,y) == check) assert N.all(using_zip(x,y) == check) assert N.all(using_custom_iteration(x,y) == check)
_______________________________________________ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion