A Monday 17 May 2010 20:11:28 Keith Goodman escrigué: > On Mon, May 17, 2010 at 11:06 AM, Francesc Alted <[email protected]> wrote: > > A Sunday 16 May 2010 21:14:34 Davide Lasagna escrigué: > >> 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. > > > > Both y[1:] and y[:-1] are views of the original y array, so you are not > > wasting temporary space here. So, as I see this, the above idiom is as > > efficient as it can get in terms of memory usage. > > I thought that this > > y[:-1] += y[1:] > > uses half the memory of this > > bases = y[1:] + y[:-1]
Indeed. But that way you are altering the contents of the original y array and I'm not sure if this is what the OP wanted. -- Francesc Alted _______________________________________________ NumPy-Discussion mailing list [email protected] http://mail.scipy.org/mailman/listinfo/numpy-discussion
