Re: [Numpy-discussion] Optimizing mean(axis=0) on a 3D array

2006-08-28 Thread Martin Spacek
Martin Spacek wrote: > > Actually, your original version is just as fast as the take() version. > Both are about 9X faster than numpy.mean() on my system. I prefer the > take() version because you only have to pass a single argument to > mean_accum() I forgot to mention that all my indices ar

Re: [Numpy-discussion] Optimizing mean(axis=0) on a 3D array

2006-08-28 Thread Martin Spacek
Tim Hochberg wrote: > I'm actually surprised that the take version is faster than my original > version since it makes a big ol' copy. I guess this is an indication > that indexing is more expensive than I realize. That's why nothing beats > measuring! Actually, your original version is just

Re: [Numpy-discussion] Optimizing mean(axis=0) on a 3D array

2006-08-27 Thread Tim Hochberg
Martin Spacek wrote: > Tim Hochberg wrote: > > >> Here's an approach (mean_accumulate) that avoids making any copies of >> the data. It runs almost 4x as fast as your approach (called baseline >> here) on my box. Perhaps this will be useful: >> >> > --snip-- > >> def mean_accumulate(da

Re: [Numpy-discussion] Optimizing mean(axis=0) on a 3D array

2006-08-27 Thread Martin Spacek
Tim Hochberg wrote: > Here's an approach (mean_accumulate) that avoids making any copies of > the data. It runs almost 4x as fast as your approach (called baseline > here) on my box. Perhaps this will be useful: > --snip-- > def mean_accumulate(data, indices): > result = np.zeros([32, 32],

Re: [Numpy-discussion] Optimizing mean(axis=0) on a 3D array

2006-08-27 Thread Martin Spacek
Travis Oliphant wrote: > > If frameis is 1-D, then you should be able to use > > temp = data.take(frameis,axis=0) > > for the first step. This can be quite a bit faster (and is a big > reason why take is still around). There are several reasons for this > (one of which is that index check

Re: [Numpy-discussion] Optimizing mean(axis=0) on a 3D array

2006-08-26 Thread Francesc Altet
A Dissabte 26 Agost 2006 12:26, Travis Oliphant va escriure: > If frameis is 1-D, then you should be able to use > > temp = data.take(frameis,axis=0) > > for the first step. This can be quite a bit faster (and is a big > reason why take is still around). There are several reasons for this > (on

Re: [Numpy-discussion] Optimizing mean(axis=0) on a 3D array

2006-08-26 Thread Tim Hochberg
Martin Spacek wrote: > Hello, > > I'm a bit ignorant of optimization in numpy. > > I have a movie with 65535 32x32 frames stored in a 3D array of uint8 > with shape (65535, 32, 32). I load it from an open file f like this: > > >>> import numpy as np > >>> data = np.fromfile(f, np.uint8, count=65

Re: [Numpy-discussion] Optimizing mean(axis=0) on a 3D array

2006-08-26 Thread Travis Oliphant
Martin Spacek wrote: > Hello, > > I'm a bit ignorant of optimization in numpy. > > I have a movie with 65535 32x32 frames stored in a 3D array of uint8 > with shape (65535, 32, 32). I load it from an open file f like this: > > >>> import numpy as np > >>> data = np.fromfile(f, np.uint8, count=65