numpy - Take laplacian of unevenly sampled data in python -


i have bunch of unevenly sampled (1-d) data in form of x , y values take laplacian of. there easy way in numpy/scipy?

i thinking of taking gradient of gradient, wouldn't introduce artifacts, in evenly sampled data? eg, given data 0,0,0,4,8,8,8 , 1d laplace operator 1,-2,1, laplacian 0,0,4,0,-4,0,0, using gradient of gradient yield 0,1,2,0,-2,-1,0

one way of arriving @ [1, -2, 1] operator evenly spaced grids either compute first derivatives forward difference scheme, , second backwards difference scheme, or viceversa, since both yield same result. option uneven grid both ways , average results.

lets looking @ grid point hb ahead of previous grid point, , hf behind next one:

--+----+----+---  x-hb  x   x+hb  

if didn't mess algebra, laplacian @ x computed average described above be:

(f(x+hf)*(1+hb/hf) + f(x)(2+hb/hf+hf/hb) + f(x-hb)(1+hf/hb)) / (2*hf*hb) 

you can compute on 1d array doing:

def laplacian(x, y):     x = np.asarray(x)     y = np.asarray(y)     hb = x[1:-1] - x[:-2]     hf = x[2:] - x[1:-1]     y_hb = y[:-2]     y_hf = y[2:]     hb_hf = hb / hf     hf_hb = hf / hb     return (y_hf*(1+hb_hf) - y[1:-1]*(2+hb_hf+hf_hb) +             y_hb*(1+hf_hb)) / 2 / hb / hf  >>> laplacian(range(7), [0,0,0,4,8,8,8]) array([ 0.,  4.,  0., -4.,  0.]) 

Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -