[Numpy-discussion] Speedup a code using apply_along_axis
Sun Feb 28 13:17:07 CST 2010
On Sun, Feb 28, 2010 at 1:51 PM, Xavier Gnata <firstname.lastname@example.org> wrote:
> I'm sure I reinventing the wheel with the following code:
> from numpy import *
> from scipy import polyfit,stats
> def f(x,y,z):
> return x+y+z
> def foo(M):
is this really what you want? I think this returns the indices not the values
> return polyfit(t,ramp,1)
> return 0
> print apply_along_axis(foo,2,M)
> In real life M is not the result of one fromfunction call but it does
> not matter.
> The basic idea is to compute the slope (and only the slope) along one
> axis of 3D array.
> Only the values below a given threshold should be taken into account.
> The current code is ugly and slow.
> How to remove the len and the if statement?
> How to rewrite the code in a numpy oriented way?
Getting the slope or the linear fit can be done completely vectorized
see numpy-discussion threads last April with titles
"polyfit on multiple data points" "polyfit performance"
> NumPy-Discussion mailing list
More information about the NumPy-Discussion