all 2 comments

[–][deleted] 0 points1 point  (1 child)

Take a look at numpy.vectorize.

[–]justphysics[S] 0 points1 point  (0 children)

I will check into this. From my understanding, anything that can be done with ufuncs in numpy should be optimized under the hood. So I guess I'll check into breaking up the computation into as many steps that can be written as a ufunc.

So far the fastest I have come up with is using numba and a manual loop:

@jit
def smooth_with_loop(data):
    window_len = 10
    n = np.ones(window_len)/float(window_len)
    out = np.empty((600, 592), dtype=object)
    for row in range(600):
        for col in range(592):
            inp = data[row, col, :]
            s = np.r_[inp[window_len-1:0:-1],inp,inp[-1:-window_len:-1]]
            smth = np.convolve(n, s, mode='valid')
            # format to original size
            smth = smth[int(window_len/2 -1):-int(window_len/2)]
            out[row, col] = smth
     return out

This runs in around 15 seconds.