[Numpy-discussion] an np.arange for arrays?

David Warde-Farley dwf at cs.toronto.edu
Fri Jul 10 16:06:52 EDT 2009


On 10-Jul-09, at 1:26 PM, David Goldsmith wrote:

> grid = np.array([np.linspace(x[i],y[i],nrows) for i in  
> range(len(x))]).T

Indeed, linspace will work, but careful with Python loops though,  
it'll be 2x to 6x slower (based on my empirical fiddling) than the  
solution involving mgrid.

In [31]: X = arange(10); Y = arange(10)+1
In [32]: timeit grid = np.array([np.linspace(X[i],Y[i],20) for i in  
range(len(X))]).T
1000 loops, best of 3: 424 us per loop

In [33]: timeit interp_grid_thingie(X, Y, 20)
10000 loops, best of 3: 79.9 us per loop

David



More information about the NumPy-Discussion mailing list