[Numpy-discussion] faster code

Keith Goodman kwgoodman at gmail.com
Sun May 16 15:24:56 EDT 2010


On Sun, May 16, 2010 at 12:14 PM, Davide Lasagna
<lasagnadavide at gmail.com> wrote:
> Hi all,
> What is the fastest and lowest memory consumption way to compute this?
> y = np.arange(2**24)
> bases = y[1:] + y[:-1]
> Actually it is already quite fast, but i'm not sure whether it is occupying
> some temporary memory
> is the summation. Any help is appreciated.

Is it OK to modify y? If so:

>> y = np.arange(2**24)
>> z = y[1:] + y[:-1]  # <--- Slow way
>> y[:-1] += y[1:]  # <--- Fast way
>> (y[:-1] == z).all()
   True



More information about the NumPy-Discussion mailing list