On Wed, Sep 14, 2011 at 4:25 PM, Christopher Barker <Chris.Barker@noaa.gov> wrote:
On 9/14/11 1:01 PM, Christopher Barker wrote:
> numpy.ndarray.resize is a different method, and I'm pretty sure it
> should be as fast or faster that np.empty + np.append.

My profile:

In [25]: %timeit f1 # numpy.resize()
10000000 loops, best of 3: 163 ns per loop

In [26]: %timeit f2 #numpy.ndarray.resize()
10000000 loops, best of 3: 136 ns per loop

In [27]: %timeit f3 # numpy.empty() + append()
10000000 loops, best of 3: 136 ns per loop


those last two couldn't b more identical!

(though this is an excercise in unrequired optimization!)


Are you sure the f2 code works?  a.resize() takes only a shape tuple.  As coded, you should get an exception.

Ben Root