On Wed, Mar 19, 2008 at 12:57 PM, Peter Creasey <[EMAIL PROTECTED]> wrote: > Hi, > > I'm trying to do a PDE style calculation with numpy arrays > > y = a * x[:-2] + b * x[1:-1] + c * x[2:] > > with a,b,c constants. I realise I could use correlate for this, i.e > > y = numpy.correlate(x, array((a, b, c))) > > however the performance doesn't seem as good (I suspect correlate is > optimised for both arguments being long arrays). Is the first thing I > wrote probably the best? Or is there a better numpy function for this > case?
The relative performance seems to vary depending on the size, but it seems to me that correlate usually beats the manual implementation, particularly if you don't measure the array() part, too. len(x)=1000 is the only size where the manual version seems to beat correlate on my machine. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco _______________________________________________ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion